Skip to content

Version 4.0.0 - #12

Merged
igoramadas merged 12 commits into
masterfrom
v4
Oct 7, 2026
Merged

igoramadas merged 12 commits into
masterfrom
v4

Conversation

@igoramadas

@igoramadas igoramadas commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Anyhow 4.0.0

Native ESM support

The package now ships both CommonJS and ESM entry points through package.json exports. Both require("anyhow") and import logger from "anyhow" resolve to the same singleton instance, with matching type declarations for each format.

Node.js 22 or newer (breaking)

The minimum supported Node.js version is now 22. The TypeScript configuration targets modern Node module resolution.

New levelMap option

Maps Anyhow levels to the level names supported by the configured logger or console, for example {debug: "trace"}. Enabled levels and console styles still use the original Anyhow level; only the level passed to the logger or the console method changes.

Full JSON on debug()

debug() now logs the full JSON of the passed objects, keeping nested arrays and string values intact. Only the maskSecrets preprocessor runs for debug logs, so secrets are still masked.

Other changes

  • Fixed unhandledRejections: false not removing the registered handler.

@igoramadas igoramadas mentioned this pull request Oct 7, 2026
@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Upgrades Node.js version requirement and adds ESM support.

The recent changes appear safe to merge, with a non-blocking issue affecting logs that contain nested buffers.

Reviews (3) · Last reviewed commit: "Updated changelog." · Reviewed by Greptile

Comment thread README.md Outdated
@greptile-apps

This comment has been minimized.

@igoramadas
igoramadas marked this pull request as ready for review October 7, 2026 18:23
Comment thread src/utils.ts
Comment on lines +35 to +36
for (const key of Object.keys(obj)) {
result[key] = cloneDeep(obj[key], logErrors, maxDepth, depth + 1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Nested buffers hide log details

With preprocessors: ["maskSecrets"] and the default clone: true, logging {payload: Buffer.from("abc"), message: "request failed"} now produces "[object Object]" instead of JSON. The recursive copy gives the nested buffer Buffer.prototype but no backing bytes. Its toJSON() fails, so argumentsParser falls back to the outer object's string, hiding even its ordinary fields.

Previously, the shallow copy preserved the nested buffer. Copy buffers with Buffer.from() before the generic object branch.

Fix in Cursor

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in b941f5a. cloneDeep now only copies plain objects, arrays, errors and dates. Buffers, other built-ins and class instances are kept as they are, so the nested buffer serializes as before.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 39 files

Confidence score: 4/5

  • In src/preprocessors.ts, friendlyErrors treats successful fetch responses as failures, so they can be logged as Code 200 | OK. Only extract error details when obj.ok === false.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/preprocessors.ts">

<violation number="1" location="src/preprocessors.ts:150">
P2: `friendlyErrors` treats successful fetch responses as failures because this condition only checks that `ok` is boolean. Logging a successful `Response` becomes `Code 200 | OK`; require `obj.ok === false` before extracting failure details.</violation>
</file>

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Turn on auto-fix | Re-trigger cubic

Comment thread src/index.ts
Comment thread src/preprocessors.ts
}

// Failed fetch() response, the body can't be read synchronously.
else if (typeof obj.ok == "boolean" && typeof obj.status == "number" && isFunction(obj.headers?.get)) {

@cubic-dev-ai cubic-dev-ai Bot Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: friendlyErrors treats successful fetch responses as failures because this condition only checks that ok is boolean. Logging a successful Response becomes Code 200 | OK; require obj.ok === false before extracting failure details.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/preprocessors.ts, line 150:

<comment>`friendlyErrors` treats successful fetch responses as failures because this condition only checks that `ok` is boolean. Logging a successful `Response` becomes `Code 200 | OK`; require `obj.ok === false` before extracting failure details.</comment>

<file context>
@@ -138,6 +140,16 @@ class AnyhowPreProcessors {
+            }
+
+            // Failed fetch() response, the body can't be read synchronously.
+            else if (typeof obj.ok == "boolean" && typeof obj.status == "number" && isFunction(obj.headers?.get)) {
+                arrError.push(`Code ${obj.status}`)
+                if (obj.statusText) arrError.push(obj.statusText)
</file context>
Suggested change
else if (typeof obj.ok == "boolean" && typeof obj.status == "number" && isFunction(obj.headers?.get)) {
else if (obj.ok === false && typeof obj.status == "number" && isFunction(obj.headers?.get)) {
Fix with cubic

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Not changing this one. The output only shows the status, it doesn't label the response as an error. Requiring ok === false would make a successful Response log as {}, since all its properties are getters, which loses useful information.

Comment thread src/utils.ts
Comment thread src/utils.ts Outdated
Comment thread test/test-esm.mjs Outdated
Comment thread test/test-a.ts
Comment thread test/test-gcloud.ts
@igoramadas
igoramadas merged commit 802d7ba into master Oct 7, 2026
3 checks passed
@igoramadas
igoramadas deleted the v4 branch October 7, 2026 18:45
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.

1 participant