Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

The logger crashed with The "createClient-0-start" performance mark has not been set when DEBUG=true was enabled. This occurred when report() attempted to measure events that hadn't been properly ended, either due to early returns or runtime errors.

Changes

  • Added defensive event lifecycle management: endAllEvents() recursively ensures all events have end marks before measurement
  • Added error recovery: Wrapped performance.measure() calls in try-catch to gracefully skip reporting when marks are missing
  • Added test coverage: New test suite validates logger behavior with unended events

Example

Before, this would crash:

const logger = new Logger();
const event = logger.timeEvent('task');
// event.timeEnd() not called due to error
logger.report(true); // ❌ Crashes

After:

const logger = new Logger();
const event = logger.timeEvent('task');
// event.timeEnd() not called due to error  
logger.report(true); // ✅ Silently skips reporting
Original prompt

This section details on the original issue you should resolve

<issue_title>Crash Report — performance mark has not been set</issue_title>
<issue_description>Hi there. This happens for me with @hey-api/openapi-ts@0.86.8. My repo is company-internal, but I did try to bisect and I see the issue in v0.82.4, but not in the release before it (v0.82.1).

Error: The "createClient-0-start" performance mark has not been set

Stack Trace:

SyntaxError: The "createClient-0-start" performance mark has not been set
    at getMark (node:internal/perf/usertiming:65:11)
    at calculateStartDuration (node:internal/perf/usertiming:212:13)
    at measure (node:internal/perf/usertiming:230:7)
    at Performance.measure (node:internal/perf/performance:134:12)
    at $.report (file:///Users/torarvid/oda/alma/node_modules/@hey-api/openapi-ts/dist/src-Be7tT6MZ.js:1309:3396)
    at yt (file:///Users/torarvid/oda/alma/node_modules/@hey-api/openapi-ts/dist/src-Be7tT6MZ.js:1309:5425)
```</issue_description>

<agent_instructions>The script fails when using `DEBUG=true`, figure out why and how to fix it</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@mrlubos</author><body>
@torarvid can you share your config?</body></comment_new>
<comment_new><author>@mrlubos</author><body>
Yes! Are you able to update to the latest? It's not obvious to me why this would happen, I'd need to see a reproducible example. I believe this should not exist in the latest. If it does, it would require deeper investigation</body></comment_new>
<comment_new><author>@mrlubos</author><body>
@torarvid this will be a you problem I'm afraid. Your Node.js version? How are you executing it, etc etc</body></comment_new>
<comment_new><author>@mrlubos</author><body>
that mark is created here https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/generate.ts#L51 and report only ever runs after https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/generate.ts#L101

So there's either something wrong with the Performance API on your end, or the marks get cleared somehow before the report runs</body></comment_new>
<comment_new><author>@mrlubos</author><body>
if you have the ability, you could try to mock/stub/observe the performance module and see if it exists and gets called properly https://developer.mozilla.org/en-US/docs/Web/API/Window/performance</body></comment_new>
<comment_new><author>@mrlubos</author><body>
Is it reproducible? Anything that needs to be fixed here?</body></comment_new>
<comment_new><author>@mrlubos</author><body>
@torarvid can you add a StackBlitz example?</body></comment_new>
<comment_new><author>@mrlubos</author><body>
You can open a new bug issue template and it's one of the fields there, but tl;dr you can use https://stackblitz.com/edit/hey-api-client-fetch-example to create a reproducible example</body></comment_new>
<comment_new><author>@mrlubos</author><body>
@torarvid yep, I can reproduce even locally now – very interesting! Also fun you discovered another quirk in StackBlitz, didn't know that either</body></comment_new>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2025

🦋 Changeset detected

Latest commit: d5c0a1c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hey-api/openapi-ts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hey-api-docs Ready Ready Preview Comment Oct 29, 2025 11:41pm

…ling

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix crash report for performance mark not being set Fix performance mark crash when using DEBUG=true Oct 29, 2025
Copilot AI requested a review from mrlubos October 29, 2025 22:45
Copilot finished work on behalf of mrlubos October 29, 2025 22:45
@mrlubos mrlubos marked this pull request as ready for review October 29, 2025 23:36
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug 🔥 Something isn't working labels Oct 29, 2025
@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

❌ Patch coverage is 32.30769% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 30.01%. Comparing base (ff89df2) to head (d5c0a1c).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
packages/openapi-ts/src/utils/logger.ts 32.30% 44 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2884      +/-   ##
==========================================
- Coverage   30.05%   30.01%   -0.05%     
==========================================
  Files         488      488              
  Lines       40337    40423      +86     
  Branches     2422     2427       +5     
==========================================
+ Hits        12122    12131       +9     
- Misses      28181    28258      +77     
  Partials       34       34              
Flag Coverage Δ
unittests 30.01% <32.30%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@mrlubos mrlubos left a comment

Choose a reason for hiding this comment

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

Nice one!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 29, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 29, 2025

Open in StackBlitz

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@2884
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2884
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2884
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2884

commit: d5c0a1c

@mrlubos mrlubos merged commit c6de684 into main Oct 29, 2025
16 of 17 checks passed
@mrlubos mrlubos deleted the copilot/fix-performance-mark-issue branch October 29, 2025 23:54
@hey-api hey-api bot mentioned this pull request Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🔥 Something isn't working lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash Report — performance mark has not been set

2 participants