Safely parse malformed input
Parsing user-provided JSON needs a failure path. Successful parsing alone does not establish that the result has the expected shape.
Developer journal
Server-side JavaScript, streams, files, diagnostics and runtime behaviour.
Parsing user-provided JSON needs a failure path. Successful parsing alone does not establish that the result has the expected shape.
CRC32 is useful for detecting accidental changes to a byte sequence. Record the input encoding so different producers compute the same checksum.
Performance marks can carry details about the operation they describe. Small stable identifiers are easier to aggregate than large payloads.
Process arguments include runtime and entry-point information before user arguments. Slice off those positions before interpreting input.
An event name can exist without listeners at the point of inspection. Listener checks are snapshots of registration state.
An ASCII check operates on bytes. A string that looks simple after display normalization may still require multibyte encoding.
Random byte counts describe entropy-bearing bytes, not the final string length. Hex and base64 encode the same bytes at different lengths.
A streamed JSON document must be framed before parsing. A single JSON document and newline-delimited JSON have different boundaries.
Joining path segments handles separators across supported platforms. Decide whether the result is intended for a local filesystem or a web URL.
An async loop consumes a web stream chunk by chunk. Stream chunks need not align with logical messages or character boundaries.
Windows paths have their own separator and parser. Node's explicit Windows path helpers let a Linux build process inspect them predictably.
Normalizing dot segments simplifies the spelling of a path. It does not establish that the target exists or resolve symbolic links.
A promise-based delay returns control while a timer waits. It establishes a minimum delay, not an exact execution timestamp.
A response body is a consumable stream. Choose how to decode it before handing it to several readers.
Built-in module detection distinguishes runtime modules from similarly named packages. That distinction matters when reporting dependencies.
Async context is available inside the scope that established it. Code invoked outside that scope needs an explicit missing-context policy.
A file signature is more informative than an extension when identifying a candidate format. A matching prefix alone does not prove the whole file is valid.
Cloning a regular expression should preserve the source and flags your caller relies on. Stateful matching can require additional attention to position.
Error-first callbacks carry failure and success through separate arguments. Centralizing the error check makes the success path easier to inspect.
Allocating a filled buffer makes each initial byte predictable. This matters when preparing binary fixtures or constructing headers.
The size of URLSearchParams counts entries, including repeated keys. It can differ from the number of distinct parameter names.
The last extension alone cannot identify every compound file format. Treat extension parsing as a filename convention rather than content detection.
Named diagnostic channels separate event producers from subscribers. Consistent names let instrumentation attach without changing the business operation.
Resolving a relative path uses a base directory. A background job and a local shell may start from different working directories.
A regular expression may arrive from a different execution context. A runtime type check can be more reliable than inspecting a constructor name.
Reading one database row needs a defined ordering when more than one row matches. An absent match also deserves an explicit branch.
Formatted diagnostic messages combine fixed text and inspected values. Check how the formatter treats objects and unused arguments.
The basename is the last named part of a path. Removing an extension is a separate operation with case-sensitive edge cases.
Ordinal categories vary by locale. Use the category as an input to a localized suffix table instead of attaching an English ending everywhere.
File metadata describes the path at the time it was inspected. A later read can still fail if the file changes.