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

Logging and error handling for location utils #12258

Merged
merged 11 commits into from
Feb 7, 2020

Conversation

phil-hodgson
Copy link
Member

No description provided.

@satbai satbai force-pushed the users/philho/locationUtilities branch from b55e9a8 to 6885724 Compare February 4, 2020 17:25
@satbai satbai force-pushed the users/philho/locationUtilities branch from e6eb532 to 7fa9319 Compare February 4, 2020 19:26
@@ -11,7 +11,12 @@ export async function retryOnException<T>(action: () => Promise<T>, maxTries: nu
throw error;
}
tl.debug(`Attempt failed. Number of tries left: ${maxTries}`);
tl.debug(JSON.stringify(error));
if (error instanceof Error) {
Copy link
Member

Choose a reason for hiding this comment

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

Why can't use the logError function here?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's because I put the helper in packaging-common and this is in artifacts-common. I didn't want to create a dependency between the two common folders.

error
}

function log(message: string, logType: LogType) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Any reason no to default logType to debug?

Copy link
Contributor

Choose a reason for hiding this comment

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

No particular reason. This will only be called by the exported logError function below so I'll leave it as is

}

function log(message: string, logType: LogType) {
if (logType === LogType.warning) {
Copy link
Member Author

Choose a reason for hiding this comment

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

For branching behavior for enums I typically use a switch (with a "default: throw UnknownEnum"). That fails faster when a new enum value is added and the branching wasn't updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Switch is a good one. If we add more log types we can change it to a switch but since there are only three options I'll leave it as is for now. Thanks!

/**
* Logs the error instead of throwing.
*/
export function logError(error: any, logType: LogType = LogType.debug) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Consider talking to the pipelines team to see if we can add behavior to internal.ts

@satbai satbai merged commit 7bf2391 into master Feb 7, 2020
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.

3 participants