-
Notifications
You must be signed in to change notification settings - Fork 452
Tolerate errors loading repository properties #3421
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
Changes from 1 commit
e142eee
4e14537
f4b47e7
d9e374e
9fda641
9ea34c5
a0671be
e8f4871
5cb12c4
6a50972
fbf75eb
d5dd165
679da45
38ba96d
0720e13
9aa0515
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1293,32 +1293,42 @@ export function joinAtMost( | |
| return array.join(separator); | ||
| } | ||
|
|
||
| /** A success result. */ | ||
| type Success<T> = Result<T, never>; | ||
| /** A failure result. */ | ||
| type Failure<E> = Result<never, E>; | ||
|
|
||
| /** | ||
| * A simple result type representing either a success or a failure. | ||
| */ | ||
| export class Result<T, E> { | ||
| private constructor( | ||
| private readonly _ok: boolean, | ||
| public readonly value: T | E, | ||
| ) {} | ||
|
|
||
| static ok<T>(value: T): Success<T> { | ||
| /** A success result. */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: These are the same comments as for the types, but these are actually functions constructing values of those types. How about "Constructs a success result", and similarly for the failure case below? |
||
| static success<T>(value: T): Success<T> { | ||
| return new Result(true, value) as Success<T>; | ||
| } | ||
|
|
||
| static error<E>(error: E): Failure<E> { | ||
| return new Result(false, error) as Failure<E>; | ||
| /** A failure result. */ | ||
| static failure<E>(value: E): Failure<E> { | ||
| return new Result(false, value) as Failure<E>; | ||
| } | ||
|
|
||
| isOk(): this is Success<T> { | ||
| /** Whether this result represents a success. */ | ||
| isSuccess(): this is Success<T> { | ||
| return this._ok; | ||
| } | ||
|
|
||
| isError(): this is Failure<E> { | ||
| /** Whether this result represents a failure. */ | ||
| isFailure(): this is Failure<E> { | ||
| return !this._ok; | ||
| } | ||
|
|
||
| /** Get the value if this is a success, or return the default value if this is a failure. */ | ||
| orElse(defaultValue: T): T { | ||
| return this.isOk() ? this.value : defaultValue; | ||
| return this.isSuccess() ? this.value : defaultValue; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.