Skip to content

Commit

Permalink
Merge pull request #27174 from sdht0/adapter-error-codes
Browse files Browse the repository at this point in the history
adapter: adjust error codes based on severity
  • Loading branch information
maddyblue authored May 23, 2024
2 parents 7489165 + cf2bf74 commit 1104524
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
35 changes: 19 additions & 16 deletions src/adapter/src/notice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,34 +259,37 @@ impl AdapterNotice {
AdapterNotice::ExplicitTransactionControlInImplicitTransaction => {
SqlState::NO_ACTIVE_SQL_TRANSACTION
}
AdapterNotice::UserRequested { .. } => SqlState::WARNING,
AdapterNotice::ClusterReplicaStatusChanged { .. } => SqlState::WARNING,
AdapterNotice::UserRequested { severity } => match severity {
NoticeSeverity::Warning => SqlState::WARNING,
_ => SqlState::SUCCESSFUL_COMPLETION,
},
AdapterNotice::ClusterReplicaStatusChanged { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::CascadeDroppedObject { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::DroppedActiveDatabase { .. } => SqlState::from_code("MZ002"),
AdapterNotice::DroppedActiveCluster { .. } => SqlState::from_code("MZ003"),
AdapterNotice::QueryTimestamp { .. } => SqlState::WARNING,
AdapterNotice::EqualSubscribeBounds { .. } => SqlState::WARNING,
AdapterNotice::QueryTrace { .. } => SqlState::WARNING,
AdapterNotice::UnimplementedIsolationLevel { .. } => SqlState::WARNING,
AdapterNotice::StrongSessionSerializable => SqlState::WARNING,
AdapterNotice::BadStartupSetting { .. } => SqlState::WARNING,
AdapterNotice::RbacUserDisabled => SqlState::WARNING,
AdapterNotice::RoleMembershipAlreadyExists { .. } => SqlState::WARNING,
AdapterNotice::QueryTimestamp { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::EqualSubscribeBounds { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::QueryTrace { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::UnimplementedIsolationLevel { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::StrongSessionSerializable => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::BadStartupSetting { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::RbacUserDisabled => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::RoleMembershipAlreadyExists { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::RoleMembershipDoesNotExists { .. } => SqlState::WARNING,
AdapterNotice::AutoRunOnIntrospectionCluster => SqlState::WARNING,
AdapterNotice::AutoRunOnIntrospectionCluster => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::AlterIndexOwner { .. } => SqlState::WARNING,
AdapterNotice::CannotRevoke { .. } => SqlState::WARNING,
AdapterNotice::NonApplicablePrivilegeTypes { .. } => SqlState::WARNING,
AdapterNotice::CannotRevoke { .. } => SqlState::WARNING_PRIVILEGE_NOT_REVOKED,
AdapterNotice::NonApplicablePrivilegeTypes { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::PlanNotice(plan) => match plan {
PlanNotice::ObjectDoesNotExist { .. } => SqlState::UNDEFINED_OBJECT,
PlanNotice::UpsertSinkKeyNotEnforced { .. } => SqlState::WARNING,
},
AdapterNotice::UnknownSessionDatabase(_) => SqlState::from_code("MZ004"),
AdapterNotice::DefaultClusterDoesNotExist { .. } => SqlState::from_code("MZ005"),
AdapterNotice::OptimizerNotice { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::DroppedInUseIndex { .. } => SqlState::WARNING,
AdapterNotice::WebhookSourceCreated { .. } => SqlState::WARNING,
AdapterNotice::PerReplicaLogRead { .. } => SqlState::WARNING,
AdapterNotice::DroppedInUseIndex { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::WebhookSourceCreated { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::PerReplicaLogRead { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::VarDefaultUpdated { .. } => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::Welcome(_) => SqlState::SUCCESSFUL_COMPLETION,
AdapterNotice::PlanInsights(_) => SqlState::from_code("MZ001"),
Expand Down
2 changes: 1 addition & 1 deletion src/environmentd/tests/testdata/http/ws
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ ws-text
ws-text
{"query":"SELECT 1 FROM mz_sources LIMIT 1"}
----
{"type":"Notice","payload":{"message":"query was automatically run on the \"mz_introspection\" cluster","code":"01000","severity":"debug"}}
{"type":"Notice","payload":{"message":"query was automatically run on the \"mz_introspection\" cluster","code":"00000","severity":"debug"}}
{"type":"CommandStarting","payload":{"has_rows":true,"is_streaming":false}}
{"type":"Rows","payload":{"columns":[{"name":"?column?","type_oid":23,"type_len":4,"type_mod":-1}]}}
{"type":"Row","payload":["1"]}
Expand Down
22 changes: 11 additions & 11 deletions test/pgtest-mz/notice.pt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ CommandComplete {"tag":"CREATE INDEX"}
ReadyForQuery {"status":"I"}
CommandComplete {"tag":"DROP INDEX"}
ReadyForQuery {"status":"I"}
NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"01000"}]}
NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"00000"}]}
CommandComplete {"tag":"DROP INDEX"}
ReadyForQuery {"status":"I"}
CommandComplete {"tag":"DROP MATERIALIZED VIEW"}
Expand All @@ -87,14 +87,14 @@ CommandComplete {"tag":"CREATE INDEX"}
ReadyForQuery {"status":"I"}
CommandComplete {"tag":"CREATE MATERIALIZED VIEW"}
ReadyForQuery {"status":"I"}
NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"01000"}]}
NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"00000"}]}
CommandComplete {"tag":"DROP INDEX"}
ReadyForQuery {"status":"I"}
CommandComplete {"tag":"CREATE INDEX"}
ReadyForQuery {"status":"I"}
CommandComplete {"tag":"CREATE INDEX"}
ReadyForQuery {"status":"I"}
NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"01000"}]}
NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"00000"}]}
CommandComplete {"tag":"DROP INDEX"}
ReadyForQuery {"status":"I"}
CommandComplete {"tag":"DROP INDEX"}
Expand Down Expand Up @@ -323,10 +323,10 @@ CommandComplete {"tag":"CREATE DATABASE"}
ReadyForQuery {"status":"I"}
CommandComplete {"tag":"SET"}
ReadyForQuery {"status":"I"}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for CLUSTER \"quickstart\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for DATABASE \"materialize\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for SCHEMA \"materialize.public\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for SYSTEM"}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for CLUSTER \"quickstart\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for DATABASE \"materialize\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for SCHEMA \"materialize.public\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for SYSTEM"}]}
NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"MZ002"},{"typ":"M","value":"active database \"d4\" has been dropped"}]}
CommandComplete {"tag":"DROP OWNED"}
ReadyForQuery {"status":"I"}
Expand Down Expand Up @@ -388,10 +388,10 @@ CommandComplete {"tag":"CREATE CLUSTER"}
ReadyForQuery {"status":"I"}
CommandComplete {"tag":"SET"}
ReadyForQuery {"status":"I"}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for CLUSTER \"quickstart\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for DATABASE \"materialize\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for SCHEMA \"materialize.public\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01000"},{"typ":"M","value":"no privileges could be revoked for SYSTEM"}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for CLUSTER \"quickstart\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for DATABASE \"materialize\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for SCHEMA \"materialize.public\""}]}
NoticeResponse {"fields":[{"typ":"S","value":"WARNING"},{"typ":"C","value":"01006"},{"typ":"M","value":"no privileges could be revoked for SYSTEM"}]}
NoticeResponse {"fields":[{"typ":"S","value":"NOTICE"},{"typ":"C","value":"MZ003"},{"typ":"M","value":"active cluster \"c4\" has been dropped"}]}
CommandComplete {"tag":"DROP OWNED"}
ReadyForQuery {"status":"I"}
Expand Down

0 comments on commit 1104524

Please sign in to comment.