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

feat: logger and emit errors #39

Merged
merged 7 commits into from
Jan 18, 2021
Merged

feat: logger and emit errors #39

merged 7 commits into from
Jan 18, 2021

Conversation

robertsLando
Copy link
Member

@robertsLando robertsLando commented Jan 15, 2021

Fixes #38
Fixes #37

src/lib/server.ts Outdated Show resolved Hide resolved
}

export interface Logger {
error(message: string | Error, error?: Error): void;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say that all logger functions should define the argument lists as ...args: unknown[].

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think typing it is ok, since that shows what we will pass to it. Typescript looks at the type, not the interface that defined the type, so if someone passes a compatible logging object, it's all good. With unknown we couldn't communicate to consumers of this lib if the data we pass changes in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

While I agree on properly typing the interfaces whenever it's possible I don't see much sense to do it for logger's functions parameters, where we should be able to pass anything we want (as i.e. console family does it).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I honestly don't really care about the logger. For all I care we keep it undefined 🤷

@@ -1,5 +1,5 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should remove this file and add it to gitignore.

@robertsLando
Copy link
Member Author

In your opinion should we remove async from start and emit the listening event instead? Like we do for error? Like a normal server does @balloob @Michsior14

@balloob
Copy link
Collaborator

balloob commented Jan 16, 2021

Porque no los dos?

@balloob
Copy link
Collaborator

balloob commented Jan 16, 2021

"Normal server" 🤷

Async awaiting a task is absolutely preferred. It means you know the error that is raised is related to you calling that function. An error event can be emitted by any other action that is currently in progress.

@@ -2,7 +2,6 @@ node_modules
package-lock.json
config.json
/dist/
.vscode/*
Copy link
Contributor

Choose a reason for hiding this comment

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

This one ignores .vscode folder ;)

I guess you should just remove the 4 lines bellow.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Michsior14 Yep, @balloob said to ignore the settings.json file but atm that's the only one file inside that folder so why not ignore the entire folder?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, this is why I suggested to remove lines like !.vscode/settings.json. The above comment was added when you removed this line (.vscode/*) ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's there... I removed it in one commit to be able to remove the folder, then in the next commit I have readded it

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep I know, it's just outdated comment now.
BTW. git rm is a easier way to do it ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

@Michsior14 Didn't know about git rm command 😆


export interface Logger {
error(message: string | Error, error?: Error): void;
warn(message: string[]): void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this one an array?

Copy link
Member Author

Choose a reason for hiding this comment

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

typo, fixing

src/lib/server.ts Outdated Show resolved Hide resolved
@balloob balloob merged commit 2d55867 into master Jan 18, 2021
@balloob balloob deleted the logger branch January 18, 2021 12:57
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.

Emit listening event instead of await it Allow to pass custom logger to zwavejs server options
3 participants