Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(error): report the error's source chain through psql #13264

Merged
merged 15 commits into from
Nov 9, 2023
Prev Previous commit
Next Next commit
gate on pretty error
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
BugenZhao committed Nov 7, 2023

Verified

This commit was signed with the committer’s verified signature.
KyleFromNVIDIA Kyle Edwards
commit a474acbc5d9a1ff33cfb6b9d844e21c06a7bf756
7 changes: 6 additions & 1 deletion src/utils/pgwire/src/pg_message.rs
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ use std::io::{Error, ErrorKind, IoSlice, Result, Write};
use byteorder::{BigEndian, ByteOrder};
/// Part of code learned from <https://github.com/zenithdb/zenith/blob/main/zenith_utils/src/pq_proto.rs>.
use bytes::{Buf, BufMut, Bytes, BytesMut};
use risingwave_common::util::env_var::env_var_is_true;
use tokio::io::{AsyncRead, AsyncReadExt};

use crate::error_or_notice::ErrorOrNoticeMessage;
@@ -634,7 +635,11 @@ impl<'a> BeMessage<'a> {

// 'E' signalizes ErrorResponse messages
buf.put_u8(b'E');
let msg = format!("{:#}", error.as_ref().as_report());
let msg = if env_var_is_true("RW_PRETTY_ERROR") {
format!("{:#}", error.as_ref().as_report())
} else {
format!("{}", error.as_ref().as_report())
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we ever want the Compact behavior? I prefer not to offer too many choices unless there's a good reason.

Copy link
Member

@xxchan xxchan Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, can we add a test (maybe expect test) for an error message to demonstrate the error format?

Copy link
Member Author

@BugenZhao BugenZhao Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we ever want the Compact behavior?

This could be a temporary workaround. 😕 SQL logic tests and planner tests are heavily relying on the error message, and I don't want to mess them into this PR.

Also, I'm not sure if the developers writing SQL logic tests are intended to match the full messages (instead of the interesting part only), like below. If so, then Pretty will be less friendly.

statement error internal error: invalid digit found in string

statement error QueryError: Bind error: update modifying the PK column is unsupported

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, can we add a test (maybe expect test) for an error message to demonstrate the error format?

There's one in thiserror-ext. Do you want another one for RisingWave's real cases? Then I'll write an integration test connecting to the pgwire server.

Copy link
Member

@xxchan xxchan Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a temporary workaround. 😕 SQL logic tests and planner tests are heavily relying on the error message, and I don't want to mess them into this PR.

If DX is the only concern or trouble, I think we should try to fix it now or later. At least pretty should be the default behavior. (Otherwise what's the meaning of these work? lol)

I think it's ok to update tests in this PR, as the core changes are very small.

If you don't want to do it now, maybe we should introduce RW_COMPACT_ERROR, instead of RW_PRETTY_ERROR.

Do you want another one for RisingWave's real cases?

Yes, that's preferred. So that we can prevent either risingwave or thiserror-ext's unexpected changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update error messages in slt and pretty is always enabled now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want another one for RisingWave's real cases?

Yes, that's preferred. So that we can prevent either risingwave or thiserror-ext's unexpected changes.

I find the error message is not good enough... Maybe let's do this in future PRs. 🤡

Copy link
Member

@xxchan xxchan Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK if the error message is not good. Just have a expect-test to let us know what's the current status is enough. 🤣 And we can see more easily how it's improved in future PRs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find writing tests with madsim is the easiest way, but the udf example does not work there. 🤡

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤡

write_err_or_notice(buf, &ErrorOrNoticeMessage::internal_error(&msg))?;
}