-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Feature/better error management #1168
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
Feature/better error management #1168
Conversation
… into feature/better_error_management
test/custom-parser.test.js
Outdated
| t.strictDeepEqual(JSON.parse(body.toString()), { | ||
| statusCode: 413, | ||
| statusCode: expectedError.statusCode, | ||
| code: expectedError.code, |
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 think we should keep those explicit in the tests
test/custom-parser.test.js
Outdated
| t.fail() | ||
| } catch (err) { | ||
| t.is(err.message, 'The content type should be a string') | ||
| t.is(err.message, new FST_ERR_CTP_INVALID_TYPE().message) |
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 would prefer for the message to be explicit here.
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.
What's the benefit? I think the error name is already very explicit. In that way we can avoid modifying all tests when we change something in the future.
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.
Sure, but I would love to avoid testing all errors individually.
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
@StarpTech any updates here? |
|
I will work on it in smaller updates I'm too busy right now. Any help is welcome. |
|
@StarpTech happy to help, what's left to do can you provide some kind of check list? |
|
@cemremengu sure
|
|
@StarpTech Reverted test to use string messages. It would look like this: t.strictDeepEqual(JSON.parse(body.toString()), {
statusCode: 413,
code: "FST_ERR_CTP_BODY_TOO_LARGE",
error: 'Payload Too Large',
message: 'FST_ERR_CTP_BODY_TOO_LARGE: Request body is too large'
})Should I push to your branch with your permission? How should we progress? EDIT: |
|
I think you can push here, just not force push. |
|
EDIT: Found it, changing this // if we have failed because `resolve has thrown
// let's rethrow the error and let avvio handle it
if (err.code === 404) throw err
return swapSchemato this // if we have failed because `resolve has thrown
// let's rethrow the error and let avvio handle it
if (err.statusCode === 404) throw err
return swapSchemawill solve the problem. Maybe we can match for the real code -- I think there is problem with test('Should throw of the schema does not exists', t => {
t.plan(1)
const fastify = Fastify()
fastify.route({
method: 'GET',
url: '/:id',
schema: {
params: 'test#'
},
handler: (req, reply) => {
reply.send(typeof req.params.id)
}
})
fastify.ready(err => {
t.is(err.message, 'Schema with id \'test\' does not exist!')
})
})If I change/delete the Schemas.prototype.resolve = function (id) {
if (this.store[id] === undefined) {
const error = new Error(`Schema with id '${id}' does not exist!`)
error.code = 404
throw error
}
return this.store[id]
}Any ideas? |
mcollina
left a comment
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.
Good work so far, from a testing perspective, we need to verify both the code and the message. Sorry if I was not clear before.
|
|
||
| function noop () {} | ||
| function noop () { } | ||
|
|
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.
why this change?
test/internals/decorator.test.js
Outdated
| server.add = decorator.add | ||
| return server | ||
| function server () {} | ||
| function server () { } |
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.
why this change?
test/internals/decorator.test.js
Outdated
| function Instance () {} | ||
| Instance.prototype.test = () => {} | ||
| function Instance () { } | ||
| Instance.prototype.test = () => { } |
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.
more unneeded changes.
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.
standard --fix or vscode formatter is changing these I think. I will revert them
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 think vscode formatter, standard --fix is run every time.
test/throw.test.js
Outdated
| t.fail() | ||
| } catch (e) { | ||
| t.ok(/missing dependency/.test(e.message)) | ||
| t.ok(/FST_ERR_DEC_MISSING_DEPENDENCY/.test(e.message)) |
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 think we colluld avoid the regexp here
…use common language in error codes
|
Very good so far. What is left to do? Docs for certain. |
|
Yes, looks like only docs are outstanding. Will send them in today. |
|
@StarpTech @mcollina I think this should be good to go after some final polishing (if necessary). Let me know if anything else needs to be done. |
mcollina
left a comment
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.
LGTM with a couple of nits.
|
This PR needs to be merged by hand to keep the dual authorship of the work. |
|
@mcollina I personally don't mind and wouldn't want anyone to waste time on that. All credits goes to @StarpTech, he did most of the work anyways. |
|
Good work @cemremengu! I also don't mind. Take the easiest way. |
docs/Errros.md
Outdated
| <a id="FST_ERR_CTP_INVALID_PARSE_TYPE"></a> | ||
| ### FST_ERR_CTP_INVALID_PARSE_TYPE | ||
|
|
||
| The provided parse type is not supported. Accepted values are 'string' or 'buffer'. |
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.
Could you mark the types in "`" as well?
docs/Errros.md
Outdated
| <a id="FST_ERR_SCH_ALREADY_PRESENT"></a> | ||
| ### FST_ERR_SCH_ALREADY_PRESENT | ||
|
|
||
| A schema with the same `id` already exists. |
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.
Be consistent use id or $id.
docs/Errros.md
Outdated
| ### FST_ERR_REP_INVALID_PAYLOAD_TYPE | ||
|
|
||
| Reply payload can either be a `string` or a `Buffer`. | ||
| Reply payload can either be a `'string'` or a `'Buffer'`. |
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.
You mean without quotes right? 😄
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.
Hang on almost there 😄
StarpTech
left a comment
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.
LGTM
delvedor
left a comment
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.
LGTM
|
Ready to merge? |
|
go for it!
Il giorno ven 12 ott 2018 alle 12:37 Dustin Deus <notifications@github.com>
ha scritto:
… Ready to merge?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1168 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AADL40Z5m-nJ_VfdeI04qtl2_OzmwGjHks5ukO9lgaJpZM4WuxzC>
.
|
|
Thank you @cemremengu for takeover. |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This is a first draft of introducing error codes to fastify. It only handles the codes for the contentTypeParser.
TODO
Previous PR: #957
Checklist
npm run testandnpm run benchmark