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

fix: Added catches for primitive/null values passed as "actual" in assertObjectMatch #3468

Merged

Conversation

JakeAve
Copy link
Contributor

@JakeAve JakeAve commented Jun 26, 2023

Having issues when null and undefined are passed in the 'actual' argument for assertObjectMatch. Typeof null is 'object', so in recursion null kept being sent as a weakmap, but should have been assigned as filtered[key] = value.

Primitive types also could be passed in as the 'actual' value in JS, and they gave a cryptic weakmap error, but it's just a typeerror.

I slightly disagree with the AssertionError instead of the TypeError in issue #3451, but I'm open to suggestions.

@JakeAve JakeAve requested a review from kt3k as a code owner June 26, 2023 06:10
@JakeAve
Copy link
Contributor Author

JakeAve commented Jun 26, 2023

I know that @luk3skyw4lker looked at this too. Can we get his blessing in case he has something better?

@luk3skyw4lker
Copy link
Contributor

Hey @JakeAve maybe you should run the deno fmt command because there are many diffs that are mainly code formats and deno already has a pattern for code format.

@JakeAve
Copy link
Contributor Author

JakeAve commented Jun 26, 2023

@luk3skyw4lker I agree. @kt3k I'm on

deno 1.34.3 (release, aarch64-apple-darwin)
v8 11.5.150.2
typescript 5.0.4

but my deno fmt is changing a lot more lines than I feel like it should.

@kt3k
Copy link
Member

kt3k commented Jun 27, 2023

@JakeAve I think these formatting changes were caused by your editor settings (do you enable any auto formatter?). Deno doesn't seem introducing these changes recently (and deno fmt allows/respects some formatting variations). Could you revert the change, disable auto formatter, and redo the actual changes?

@JakeAve JakeAve force-pushed the assert-object-match-falsy-and-primitive-errors branch from 072c325 to f68e2c1 Compare June 27, 2023 14:48
Comment on lines +548 to +552
throw new TypeError(
`Cannot assertObjectMatch ${
a === null ? null : `type ${typeof a}`
}`,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about returning a here instead of throwing TypeError? That makes the case assertObjectMatch(null, { foo: 42 }) throwing more useful AssertionError instead of TypeError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to that. I feel like assertObjectMatch is supposed to be for higher ordered objects, so I've been wanting to do a typeerror, but I understand you could have a function that returns either null/undefined or an object. The problem I have is there are ts warnings whenever you try to pass something that couldn't be made into a weakmap, so if we go that route, I wonder if we update the argument types to accept more values than

actual: Record<PropertyKey, any>,
expected: Record<PropertyKey, unknown>,

I'm pushing the updates so we can see how it looks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like assertObjectMatch is supposed to be for higher ordered objects, so I've been wanting to do a typeerror

Ah, right. The previous version might make more sense. Thanks for the clarification of the reasoning.

@kt3k kt3k force-pushed the assert-object-match-falsy-and-primitive-errors branch from bb0a84a to 9a3ca1c Compare June 29, 2023 06:36
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kt3k kt3k merged commit 4026c52 into denoland:main Jun 30, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants