Repository navigation
Workflow: Address follow-ups from the TypeScript refactor #84361
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
Merged
+177
−76
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6123942
Workflow: Address follow-ups from the TypeScript refactor
manzoorwanijk 61690dc
Workflow: Add PR number to changelog entry
manzoorwanijk 45eb7ad
Workflow: Order changelog sections
manzoorwanijk 125e9b0
Workflow: Address review feedback
manzoorwanijk 7eee4c7
Workflow: Toggle the palette with a state updater
manzoorwanijk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { decodeEntities } from '@wordpress/html-entities'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| /** | ||
| * Turns whatever an ability threw into a message the user can read. | ||
| * | ||
| * @param error The value the ability threw. | ||
| * @return The message to show the user. | ||
| */ | ||
| export function getErrorMessage( error: unknown ): string { | ||
| let message = ''; | ||
| if ( typeof error === 'object' && error !== null ) { | ||
| if ( 'message' in error && typeof error.message === 'string' ) { | ||
| message = error.message; | ||
| } | ||
| // An error with an empty message still names its type, e.g. `TypeError`. | ||
| if ( ! message && 'name' in error && typeof error.name === 'string' ) { | ||
| message = error.name; | ||
| } | ||
| } else if ( error !== null && error !== undefined ) { | ||
| message = String( error ); | ||
| } | ||
|
|
||
| if ( ! message ) { | ||
| return __( | ||
| 'This ability couldn’t run. Check the browser console for details.' | ||
| ); | ||
| } | ||
|
|
||
| // REST errors can carry HTML entities, such as `’`. | ||
| return decodeEntities( message ); | ||
| } |
48 changes: 48 additions & 0 deletions
48
packages/workflow/src/utils/test/get-error-message.jsdom.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { getErrorMessage } from '../get-error-message'; | ||
|
|
||
| const FALLBACK = | ||
| 'This ability couldn’t run. Check the browser console for details.'; | ||
|
|
||
| describe( 'getErrorMessage', () => { | ||
| it.each( [ | ||
| [ 'undefined', undefined ], | ||
| [ 'null', null ], | ||
| [ 'an empty string', '' ], | ||
| [ 'a plain object without a message', { code: 'oops' } ], | ||
| ] )( 'returns the fallback for %s', ( _, error ) => { | ||
| expect( getErrorMessage( error ) ).toBe( FALLBACK ); | ||
| } ); | ||
|
|
||
| it( 'returns a thrown string', () => { | ||
| expect( getErrorMessage( 'Something broke' ) ).toBe( | ||
| 'Something broke' | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'stringifies other primitives', () => { | ||
| expect( getErrorMessage( 404 ) ).toBe( '404' ); | ||
| } ); | ||
|
|
||
| it( 'returns the message of an error', () => { | ||
| expect( getErrorMessage( new Error( 'Not allowed' ) ) ).toBe( | ||
| 'Not allowed' | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'returns the message of a plain object', () => { | ||
| expect( getErrorMessage( { message: 'REST failure' } ) ).toBe( | ||
| 'REST failure' | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'returns the name of an error with an empty message', () => { | ||
| expect( getErrorMessage( new TypeError() ) ).toBe( 'TypeError' ); | ||
| } ); | ||
|
|
||
| it( 'decodes HTML entities', () => { | ||
| expect( | ||
| getErrorMessage( { message: 'You don’t have access.' } ) | ||
| ).toBe( 'You don’t have access.' ); | ||
| } ); | ||
| } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/tsconfig.json", | ||
| "extends": "@wordpress/monorepo-tools/tsconfig/base.json", | ||
| "compilerOptions": { | ||
| "types": [ "style-imports" ] | ||
| }, | ||
| "references": [ | ||
| { "path": "../abilities/tsconfig.build.json" }, | ||
| { "path": "../components/tsconfig.build.json" }, | ||
| { "path": "../core-abilities" }, | ||
| { "path": "../data" }, | ||
| { "path": "../element/tsconfig.build.json" }, | ||
| { "path": "../html-entities/tsconfig.build.json" }, | ||
| { "path": "../i18n/tsconfig.build.json" }, | ||
| { "path": "../icons/tsconfig.build.json" }, | ||
| { "path": "../keyboard-shortcuts" }, | ||
| { "path": "../keycodes/tsconfig.build.json" }, | ||
| { "path": "../ui/tsconfig.build.json" } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,8 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/tsconfig.json", | ||
| "extends": "@wordpress/monorepo-tools/tsconfig/base.json", | ||
| "extends": "@wordpress/monorepo-tools/tsconfig/dev.base.json", | ||
| "compilerOptions": { | ||
| "types": [ "style-imports" ] | ||
| "types": [ "style-imports", "gutenberg-vitest-test-env" ] | ||
| }, | ||
| "references": [ | ||
| { "path": "../abilities/tsconfig.build.json" }, | ||
| { "path": "../components/tsconfig.build.json" }, | ||
| { "path": "../core-abilities" }, | ||
| { "path": "../data" }, | ||
| { "path": "../element/tsconfig.build.json" }, | ||
| { "path": "../i18n/tsconfig.build.json" }, | ||
| { "path": "../icons/tsconfig.build.json" }, | ||
| { "path": "../keyboard-shortcuts" }, | ||
| { "path": "../keycodes/tsconfig.build.json" }, | ||
| { "path": "../ui/tsconfig.build.json" } | ||
| ] | ||
| "references": [ { "path": "./tsconfig.build.json" } ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.