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(cli): use user-defined error hook #165

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(cli): use user-defined error hook
markthree committed Mar 7, 2024
commit 2bc08872345d7748038e7b09c413c1d7ce2242cc
8 changes: 6 additions & 2 deletions src/server/dev.ts
Original file line number Diff line number Diff line change
@@ -142,13 +142,17 @@ export async function createDevServer(

const _loadedEntry = await resolver.import(_entry);

let _handler =
_loadedEntry.handler ||
let _handler =
_loadedEntry.handler ||
_loadedEntry.handle ||
_loadedEntry.app ||
_loadedEntry.default ||
_loadedEntry;

if (_handler.options && _handler.options.onError) {
app.options.onError = _handler.options.onError;
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking we could inherit/merge all options. For example for this unjs/h3#693 (and debug option)

Copy link
Contributor Author

@markthree markthree Mar 7, 2024 β€’

Choose a reason for hiding this comment

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

Of course this would be better, but I've tested how to do the merge and some of the hooks trigger twice

for example ↓

if (_handler.options) {
  // This causes some hooks to run twice
  app.options = Object.assign(app.options, _handler.options)
}

I think this might be a bug in h3, and I think I'd have to look deeper at h3 as well.

I like unjs/h3#693,But I'd like to see the logic of your implementation, let's try to keep the behavior consistent πŸ₯°

}

if (options.ws) {
Object.assign(
dynamicWS,