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

Clarify wording around "string representation" in console.* related functions #29172

Closed
jcbhmr opened this issue Sep 17, 2023 · 5 comments · Fixed by #34284
Closed

Clarify wording around "string representation" in console.* related functions #29172

jcbhmr opened this issue Sep 17, 2023 · 5 comments · Fixed by #34284
Labels
area: Console Content:WebAPI Web API docs help wanted If you know something about this topic, we would love your help!

Comments

@jcbhmr
Copy link

jcbhmr commented Sep 17, 2023

old text

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/console/assert

What specific section or headline is this issue about?

The part about passing in objects

What information was incorrect, unhelpful, or incomplete?

What should this print?

console.assert(false, { a: 1 })

In the spec text https://console.spec.whatwg.org/#assert it would seem (from my limited understanding) that it should forward everything to Logger() and it should print Assertion failed ▶ { a: 1 } like most other console methods do. That's what Chrome and Firefox do at least.

image
image

...but then on MDN there's this text: https://developer.mozilla.org/en-US/docs/Web/API/console/assert

image
image

which reads (to me at least; i could be mistaken) that passing console.assert(false, {a:1},{b:2}) will do String() or similar on each of those {a:1} objects
...which would seem to indicate that Node.js has the right idea:
image

idk man, I'm just a bit confused which one is "right" 😂

What did you expect to see?

Rephrase the text to be a bit more clear on whether "The string representations of each of these objects are appended together in the order listed and output." means perform string coercion or print a fancy object repr.

or idk maybe a little note or some screenshots of what happens sorta like https://developer.mozilla.org/en-US/docs/Web/API/console#using_groups_in_the_console which has a very nice image

or maybe a little note about how Node.js has a slightly different way of doing it 🤷‍♂️

Do you have any supporting links, references, or citations?

https://console.spec.whatwg.org/#assert

nodejs/node#49680

whatwg/console#77

Do you have anything more you want to share?

No response

Right now in a lot of the console.* methods there's this type of language used:
image

This is potentially confusing. It seems to indicate that said objects will all be .toString()-ed and concatenated together, sorta like this:

// obj1 … objN
// A list of JavaScript objects to output. The string representations of each
// of these objects are appended together in the order listed and output.
console.info = (...objN) => {
  underlyingPrint(objN.map(x => String(x)).join(" "))
}

but that's obviously NOT what it means to convey. Instead, it means to convey that these objects are "inspected" or "pretty printed" and then "shown" (not necessarily "printed") to the console in the specified order.

The issue at hand: Should this change?

If so, here's an idea:

before after

obj1 … objN
A list of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed and output.

obj1 … objN
A list of non-string values to inspect in the console. The method of inspection is implementation defined. Browser consoles have interactive consoles, while text-based output may pretty-print the objects.

idk tho. something more clear like that

affected pages that i could find:

console.trace() has a pretty decent description https://developer.mozilla.org/en-US/docs/Web/API/console/trace

objects Optional
Zero or more objects to be output to console along with the trace. These are assembled and formatted the same way they would be if passed to the console.log() method.

@jcbhmr jcbhmr added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Sep 17, 2023
@github-actions github-actions bot added Content:WebAPI Web API docs and removed Content:WebAPI Web API docs labels Sep 17, 2023
@jcbhmr jcbhmr changed the title console.assert(condition, ...data) -- are ...data elements coerced to a string or not? What should console.assert(condition, { a: 1 }) show in the console? Sep 17, 2023
@jcbhmr jcbhmr changed the title What should console.assert(condition, { a: 1 }) show in the console? What should console.assert(false, { a: 1 }) show in the console? Sep 17, 2023
@OnkarRuikar
Copy link
Contributor

2 Let message be a string without any formatting specifiers indicating generically an assertion failure (such as "Assertion failed").

4.2 If Type(first) is not String, then prepend message to data.

As per the specs data objects are to be appended to a string (message). So the NodeJS's output Assertion failed: [object Object] is correct as per the specs.

const obj = {a:1};
const message = "Assertion failed: " + obj;
// Assertion failed: [object Object]

Unlike NodeJs, browsers can show interactable objects in the logs. Because the console logs are part of the developer tools in browsers, it is a good feature to show the objects like that. It saves us from doing console.assert(false, JSON.strigify(obj)).

@jcbhmr

This comment was marked as outdated.

@Josh-Cena
Copy link
Member

Josh-Cena commented Sep 18, 2023

Note that console spec is not a strict spec, per se—it's an attempt to find the greatest common divisor of all existing implementations. Therefore a lot of things are left very ambiguous, and so is the documentation... I'm inclined to say this is a divergence allowed in spec, whether the second arg should be a format string or a value to be directly printed.

@Josh-Cena Josh-Cena added Content:WebAPI Web API docs needs info Needs more information to review or act on. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Sep 18, 2023
@jcbhmr jcbhmr changed the title What should console.assert(false, { a: 1 }) show in the console? Clarify wording around "string representation" in console.* related functions Sep 19, 2023
@jcbhmr
Copy link
Author

jcbhmr commented Sep 19, 2023

I got my answer about "which is correct" from the whatwg/console folks: whatwg/console#226 (comment)

I've switched this issue title/text to be focused on improving the wording about "string representation concatenated together" which is more on-topic as far as MDN content is concerned. 👍

let me know your thoughts! ❤

@Josh-Cena
Copy link
Member

I think the console docs in general would benefit from some analysis of how the input is interpreted and printed, but I don't think anyone is getting to it soon.

@Josh-Cena Josh-Cena added help wanted If you know something about this topic, we would love your help! and removed needs info Needs more information to review or act on. labels Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Console Content:WebAPI Web API docs help wanted If you know something about this topic, we would love your help!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants