Skip to content

fix: migrate all throw to assert, remove optional chaining#241

Merged
tony-go merged 4 commits intomainfrom
move-throw-to-assert2
Mar 6, 2026
Merged

fix: migrate all throw to assert, remove optional chaining#241
tony-go merged 4 commits intomainfrom
move-throw-to-assert2

Conversation

@tony-go
Copy link
Copy Markdown
Contributor

@tony-go tony-go commented Mar 5, 2026

No description provided.

Comment thread index.js
return binding.sodium_compare(a, b)
}

exports.sodium_is_zero = function (buffer, length) {
if (!buffer) throw new Error('invalid buffer')
assert(ArrayBuffer.isView(buffer), 'buffer must be a typed array')
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I assumed that it was not tested as it did not break any tests... Maybe we could like to cover these? I am afraid that would be endless.

Comment thread index.js
@@ -1514,18 +1920,38 @@ exports.crypto_pwhash_scryptsalsa208sha256_str_needs_rehash = function (
// crypto_kx

exports.crypto_kx_keypair = function (pk, sk) {
if (pk?.byteLength !== binding.crypto_kx_PUBLICKEYBYTES) throw new Error('pk')
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Happy we have more explicit error now 😆

Comment thread index.js
assert(
tx.byteLength === binding.crypto_kx_SESSIONKEYBYTES,
'transmitting key buffer must be "crypto_kx_SESSIONKEYBYTES" bytes or null'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure we want to remove the or null

@tony-go tony-go requested a review from kasperisager March 5, 2026 11:15
Comment thread index.js Outdated
@tony-go tony-go requested a review from kasperisager March 5, 2026 14:01
@tony-go tony-go marked this pull request as ready for review March 5, 2026 14:06
Copy link
Copy Markdown
Contributor

@kasperisager kasperisager left a comment

Choose a reason for hiding this comment

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

Never use ==, always use === to avoid coercion surprises. Missing arguments will have a value of undefined, not null, so all the checks should be:

if (value === undefined) value = default

@tony-go
Copy link
Copy Markdown
Contributor Author

tony-go commented Mar 5, 2026

Never use ==, always use === to avoid coercion surprises. Missing arguments will have a value of undefined, not null, so all the checks should be:

if (value === undefined) value = default

Oh yeah! I thought we would have both. Which is wrong...

Signed-off-by: Tony Gorez <[email protected]>
@tony-go tony-go requested a review from kasperisager March 5, 2026 15:43
@tony-go tony-go merged commit e4e9267 into main Mar 6, 2026
3 checks passed
@tony-go tony-go deleted the move-throw-to-assert2 branch March 6, 2026 07:39
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.

2 participants