GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — doc: Fix message type in Assert docs by cottrellio · Pull Request #16427 · nodejs/node Conversation
|
|
I think {any} is fine: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thank you for responding so quickly. This is what I am experiencing. I am unable to access properties on the message of type It appears you can input {any}, but you are returned {string|undefined}. Perhaps this PR should be to add expected return types to the docs. In order to access the properties of my object message I had to JSON.stringify and then JSON.parse which defeats the purpose. try { assert.equal(1, 2, JSON.stringify({ status: 404, detail: 'Not Found' })); } catch (e) { const parsed = JSON.parse(e.message); ctx.throw(parsed.status, parsed.detail); } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@cottrellio - thanks for the quick revert. As long as a toString() is present, the data is meaningfully transported to the assertion site, but definitely not iterable, as it is now a flat string. const assert = require('assert') const util = require('util') const obj = {status: 404, detail: 'Not found', toString: () => { return "'status': 404, 'detail': 'not found'"}} try { assert.equal(1, 2, obj) } catch(e) { console.log(obj === e) console.log(util.inspect(obj, {showHidden: true, depth: null})) console.log(util.inspect(e)) } Assuming that the purpose of the assertion is to communicate the violation of a pre-condition or an un-expected program state, the Adding a caveat to the doc to this effect (that user defined objects passed to the assert will be stringified based on toString()) looks to be more reasonable to me, but let us wait for more views from other collaborators. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@gireeshpunathil Again, thank you for your response. I agree with your rational. Thank you for clarifying. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It is basically like doing: new Error({ status: 404, detail: 'Not Found' }) I think it makes sense. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
sort of stuck here. @lpinca - can you please clarify your last comment? do you endorse the changes as it is, or propose alternatives? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@gireeshpunathil I agree with what you wrote in #16427 (comment). Keeping |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
ping @nodejs/collaborators to get some concurrence on the proposal, and based on it ping @cottrellio to amend the doc accordingly |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There is no return type. const assert = require('assert'); var foo = assert.ok(true, 'message value'); console.log(foo); // undefined try { foo = assert.fail('message here'); } catch (e) { } console.log(foo); // undefined |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I'm not sure it defeats the purpose. Assertions should terminate your program. Using them for programmatic logic seems to suggest that something else would be better and/or that we're missing functionality in Node.js that needs to be added. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@cottrellio Thanks for the pull request! It seems to me like this can be closed, but if you disagree, leave a comment and we'll re-open. Hope you have everything you need! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.