-
Notifications
You must be signed in to change notification settings - Fork 40
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
report better error messages after Diesel queries #907
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,10 +183,20 @@ where | |
DieselError::DatabaseError(kind, info) => { | ||
PublicError::internal_error(&format_database_error(kind, &*info)) | ||
} | ||
error => PublicError::internal_error(&format!( | ||
"Unknown diesel error: {:?}", | ||
error | ||
)), | ||
error => { | ||
let context = match make_not_found_error() { | ||
PublicError::ObjectNotFound { type_name, lookup_type } => { | ||
format!("looking up {:?} {:?}", type_name, lookup_type) | ||
} | ||
_ => { | ||
format!("during unknown operation") | ||
} | ||
}; | ||
PublicError::internal_error(&format!( | ||
"Unknown diesel error {}: {:#}", | ||
context, error | ||
)) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -210,8 +220,8 @@ fn public_error_from_diesel_create( | |
)), | ||
}, | ||
_ => PublicError::internal_error(&format!( | ||
"Unknown diesel error: {:?}", | ||
error | ||
"Unknown diesel error creating {:?} called {:?}: {:#}", | ||
resource_type, object_name, error | ||
Comment on lines
+218
to
+219
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did these lines end up being useful? I think the change is probably good regardless, so I'm just curious if you ran into another opaque error message that this helped resolve. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I didn't wind up using these. |
||
)), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a nit, but is it true that this error is only hit when "looking up" a resource? I think your suggestion of a trait that provides an additional context method is really attractive, since it would allow us to provide this string or some other information from the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it depends on what you mean by "lookup". I believe it's always used in a context where we expect a specific object to exist and it doesn't. Sometimes that's because we're trying to update it or delete it, not fetch it. I could make the language more general ("accessing object") to avoid confusion.