diff --git a/.changeset/rare-baboons-change.md b/.changeset/rare-baboons-change.md new file mode 100644 index 0000000000..2f59cdd838 --- /dev/null +++ b/.changeset/rare-baboons-change.md @@ -0,0 +1,8 @@ +--- +"@khanacademy/perseus": major +"@khanacademy/perseus-editor": major +"@khanacademy/perseus-core": minor +"@khanacademy/perseus-linter": patch +--- + +Consolidate PerseusError code and move it into perseus-core (deletes the perseus-error package) diff --git a/packages/perseus-error/src/index.ts b/packages/perseus-core/src/error/errors.ts similarity index 73% rename from packages/perseus-error/src/index.ts rename to packages/perseus-core/src/error/errors.ts index 82c3c227e3..b980aa05d9 100644 --- a/packages/perseus-error/src/index.ts +++ b/packages/perseus-core/src/error/errors.ts @@ -1,7 +1,3 @@ -import type {Metadata} from "@khanacademy/wonder-stuff-core"; - -export {libVersion} from "./version"; - /** * @typedef {Object} Errors utility for referencing the Perseus error taxonomy. */ @@ -44,21 +40,3 @@ export const Errors = Object.freeze({ * @type {ErrorKind} The kind of error being reported */ export type ErrorKind = (typeof Errors)[keyof typeof Errors]; - -/** - * Optional extra information passed to the `PerseusError` constructor. - */ -type Options = { - metadata?: Metadata | null | undefined; -}; - -export class PerseusError extends Error { - kind: ErrorKind; - metadata: Metadata | null | undefined; - - constructor(message: string, kind: ErrorKind, options?: Options) { - super(message); - this.kind = kind; - this.metadata = options?.metadata; - } -} diff --git a/packages/perseus/src/perseus-error.ts b/packages/perseus-core/src/error/perseus-error.ts similarity index 89% rename from packages/perseus/src/perseus-error.ts rename to packages/perseus-core/src/error/perseus-error.ts index a9d3e81cf4..afc5cfd670 100644 --- a/packages/perseus/src/perseus-error.ts +++ b/packages/perseus-core/src/error/perseus-error.ts @@ -1,4 +1,4 @@ -import type {ErrorKind} from "./logging/log"; +import type {ErrorKind} from "./errors"; import type {Metadata} from "@khanacademy/wonder-stuff-core"; type Options = { diff --git a/packages/perseus-core/src/index.ts b/packages/perseus-core/src/index.ts index 3ae29fd247..a830d55cfb 100644 --- a/packages/perseus-core/src/index.ts +++ b/packages/perseus-core/src/index.ts @@ -4,8 +4,12 @@ export type { KeypadContextRendererInterface, RendererInterface, } from "./types"; +export type {ErrorKind} from "./error/errors"; // Careful, `version.ts` uses this function so it _must_ be imported above it export {addLibraryVersionToPerseusDebug} from "./utils/add-library-version-to-perseus-debug"; export {libVersion} from "./version"; + +export {Errors} from "./error/errors"; +export {PerseusError} from "./error/perseus-error"; diff --git a/packages/perseus-editor/src/article-editor.tsx b/packages/perseus-editor/src/article-editor.tsx index e2282ea05c..644e5e1b4a 100644 --- a/packages/perseus-editor/src/article-editor.tsx +++ b/packages/perseus-editor/src/article-editor.tsx @@ -4,13 +4,8 @@ * multiple (Renderer) sections concatenated together. */ -import { - components, - icons, - ApiOptions, - Errors, - PerseusError, -} from "@khanacademy/perseus"; +import {components, icons, ApiOptions} from "@khanacademy/perseus"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import * as React from "react"; import _ from "underscore"; diff --git a/packages/perseus-editor/src/editor.tsx b/packages/perseus-editor/src/editor.tsx index f2dba9d015..2024467be4 100644 --- a/packages/perseus-editor/src/editor.tsx +++ b/packages/perseus-editor/src/editor.tsx @@ -1,13 +1,12 @@ /* eslint-disable @khanacademy/ts-no-error-suppressions */ import { preprocessTex, - Errors, Log, - PerseusError, PerseusMarkdown, Util, Widgets, } from "@khanacademy/perseus"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import $ from "jquery"; // eslint-disable-next-line import/no-unresolved, import/no-extraneous-dependencies import katex from "katex"; diff --git a/packages/perseus-editor/src/widgets/cs-program-editor.tsx b/packages/perseus-editor/src/widgets/cs-program-editor.tsx index 15d495791d..7e7c9eebb4 100644 --- a/packages/perseus-editor/src/widgets/cs-program-editor.tsx +++ b/packages/perseus-editor/src/widgets/cs-program-editor.tsx @@ -8,9 +8,9 @@ import { Changeable, Dependencies, EditorJsonify, - Errors, Log, } from "@khanacademy/perseus"; +import {Errors} from "@khanacademy/perseus-core"; import $ from "jquery"; import PropTypes from "prop-types"; import * as React from "react"; diff --git a/packages/perseus-error/.eslintrc.js b/packages/perseus-error/.eslintrc.js deleted file mode 100644 index 9c878918ca..0000000000 --- a/packages/perseus-error/.eslintrc.js +++ /dev/null @@ -1,12 +0,0 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ -/* eslint-disable import/no-commonjs */ -const path = require("path"); - -module.exports = { - rules: { - "import/no-extraneous-dependencies": [ - "error", - {packageDir: [__dirname, path.join(__dirname, "../../")]}, - ], - }, -}; diff --git a/packages/perseus-error/CHANGELOG.md b/packages/perseus-error/CHANGELOG.md deleted file mode 100644 index 2cd838b9d3..0000000000 --- a/packages/perseus-error/CHANGELOG.md +++ /dev/null @@ -1,128 +0,0 @@ -# @khanacademy/perseus-error - -## 0.3.0 - -### Minor Changes - -- [#1259](https://github.com/Khan/perseus/pull/1259) [`c07644f63`](https://github.com/Khan/perseus/commit/c07644f63957ada78ba60c9b3ecd7b42e289f67b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Update all Perseus peer dependencies to match webapp exactly (commit: 2bd290251a8) - - @khanacademy/wonder-stuff-core v1.5.2 - -## 0.2.11 - -### Patch Changes - -- [#995](https://github.com/Khan/perseus/pull/995) [`a4ead994`](https://github.com/Khan/perseus/commit/a4ead9940cddc09434b823039ff51b85ecd9e639) Thanks [@benchristel](https://github.com/benchristel)! - Update formatting for Prettier 2.8.8 - -## 0.2.10 - -### Patch Changes - -- [#971](https://github.com/Khan/perseus/pull/971) [`90ff7a48`](https://github.com/Khan/perseus/commit/90ff7a483b01552a556c7852427e98153cc20417) Thanks [@benchristel](https://github.com/benchristel)! - Remove source files from the distributed NPM package - -- Updated dependencies [[`90ff7a48`](https://github.com/Khan/perseus/commit/90ff7a483b01552a556c7852427e98153cc20417)]: - - @khanacademy/perseus-core@1.4.2 - -## 0.2.9 - -### Patch Changes - -- Updated dependencies [[`1f4e17ba`](https://github.com/Khan/perseus/commit/1f4e17ba77e1491523813655af18a70285a25989), [`8857950b`](https://github.com/Khan/perseus/commit/8857950bdeeb6e13bc3766b1c6545289b21cbe2a)]: - - @khanacademy/perseus-core@1.4.1 - -## 0.2.8 - -### Patch Changes - -- [#814](https://github.com/Khan/perseus/pull/814) [`105d2060`](https://github.com/Khan/perseus/commit/105d20603d935d35cff237b17f0bfb57ca751e4c) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Minor build change to how we provide Typescript type definitions (should be no change to build output). - -- Updated dependencies [[`a91c84fe`](https://github.com/Khan/perseus/commit/a91c84fe53827ff4333220777a9918882b7fe9f0), [`105d2060`](https://github.com/Khan/perseus/commit/105d20603d935d35cff237b17f0bfb57ca751e4c)]: - - @khanacademy/perseus-core@1.4.0 - -## 0.2.7 - -### Patch Changes - -- Updated dependencies [[`79403e06`](https://github.com/Khan/perseus/commit/79403e06eedb597d7818d6c858bbba6f51ff3fe1)]: - - @khanacademy/perseus-core@1.3.0 - -## 0.2.6 - -### Patch Changes - -- Updated dependencies [[`376eb0e4`](https://github.com/Khan/perseus/commit/376eb0e4aaaa4c7a90fd6107a84bb74d382b077c)]: - - @khanacademy/perseus-core@1.2.0 - -## 0.2.5 - -### Patch Changes - -- Updated dependencies [22a9c408] - - @khanacademy/perseus-core@1.1.2 - -## 0.2.4 - -### Patch Changes - -- 55d4cd00: Print package name and version when loaded in the page -- Updated dependencies [55d4cd00] - - @khanacademy/perseus-core@1.1.1 - -## 0.2.3 - -### Patch Changes - -- 388b6506: Add comments for `Options` type. - -## 0.2.2 - -### Patch Changes - -- a383823d: Bump @khanacademy/wonder-stuff-core to v1.5.1 (which adds needed support for `isTruthy` helper function) - -## 0.2.1 - -### Patch Changes - -- 1f062e98: Bump all package versions since the build settings have been updated - -## 0.2.0 - -### Minor Changes - -- 53fd3768: Migrate source code to TypeScript - -## 0.1.5 - -### Patch Changes - -- a1b4ab3c: Update wonder-blocks and wonder-stuff deps to fix an issue with wonder-stuff's generated flow types - -## 0.1.4 - -### Patch Changes - -- 6a7f36be: Update wonder-stuff and wonder-blocks dependencies - -## 0.1.3 - -### Patch Changes - -- f567f660: Update the eslint config to look at both the package.json for the package and the one from the root - -## 0.1.2 - -### Patch Changes - -- bf180fe1: Fix our use of import/no-extraneous-dependencies - -## 0.1.1 - -### Patch Changes - -- 98d283ff: Fix storybook - -## 0.1.0 - -### Minor Changes - -- a4f10ace: Move Gorgon, PerseusError, PureMarkdown into their own packages diff --git a/packages/perseus-error/README.md b/packages/perseus-error/README.md deleted file mode 100644 index 866c081d17..0000000000 --- a/packages/perseus-error/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# @khanacademy/perseus-error - -Shared PerseusError class for errors, meant to be used throughout Perseus. - -TODO: maybe this could be part of `@khanacademy/perseus-core`? \ No newline at end of file diff --git a/packages/perseus-error/package.json b/packages/perseus-error/package.json deleted file mode 100644 index cba1ec8f34..0000000000 --- a/packages/perseus-error/package.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "@khanacademy/perseus-error", - "description": "Custom PerseusError class", - "author": "Khan Academy", - "license": "MIT", - "version": "0.3.0", - "publishConfig": { - "access": "public" - }, - "repository": { - "type": "git", - "url": "https://github.com/Khan/perseus.git", - "directory": "packages/perseus-error" - }, - "bugs": { - "url": "https://github.com/Khan/perseus/issues" - }, - "module": "dist/es/index.js", - "main": "dist/index.js", - "source": "src/index.ts", - "files": [ - "dist" - ], - "scripts": { - "test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'" - }, - "dependencies": { - "@khanacademy/perseus-core": "1.4.2" - }, - "devDependencies": { - "@khanacademy/wonder-stuff-core": "1.5.2" - }, - "peerDependencies": { - "@khanacademy/wonder-stuff-core": "1.5.2" - }, - "keywords": [] -} diff --git a/packages/perseus-error/src/version.ts b/packages/perseus-error/src/version.ts deleted file mode 100644 index 37d7275d24..0000000000 --- a/packages/perseus-error/src/version.ts +++ /dev/null @@ -1,10 +0,0 @@ -// This file is processed by a Rollup plugin (replace) to inject the production -// version number during the release build. -// In dev, you'll never see the version number. - -import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-core"; - -const libName = "@khanacademy/perseus-error"; -export const libVersion = "__lib_version__"; - -addLibraryVersionToPerseusDebug(libName, libVersion); diff --git a/packages/perseus-error/tsconfig-build.json b/packages/perseus-error/tsconfig-build.json deleted file mode 100644 index 08e1bfcdf9..0000000000 --- a/packages/perseus-error/tsconfig-build.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../tsconfig-shared.json", - "compilerOptions": { - "outDir": "./dist", - "rootDir": "src", - }, - "references": [ - {"path": "../perseus-core/tsconfig-build.json"}, - ] -} diff --git a/packages/perseus-error/types b/packages/perseus-error/types deleted file mode 120000 index 69771504f3..0000000000 --- a/packages/perseus-error/types +++ /dev/null @@ -1 +0,0 @@ -../../types/ \ No newline at end of file diff --git a/packages/perseus-linter/package.json b/packages/perseus-linter/package.json index b272876288..3f2f1fc2d3 100644 --- a/packages/perseus-linter/package.json +++ b/packages/perseus-linter/package.json @@ -25,8 +25,7 @@ "test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'" }, "dependencies": { - "@khanacademy/perseus-core": "1.4.2", - "@khanacademy/perseus-error": "^0.3.0" + "@khanacademy/perseus-core": "1.4.2" }, "devDependencies": { "@khanacademy/pure-markdown": "^0.3.5", diff --git a/packages/perseus-linter/src/rule.ts b/packages/perseus-linter/src/rule.ts index 172eb5cf82..f63c5318cb 100644 --- a/packages/perseus-linter/src/rule.ts +++ b/packages/perseus-linter/src/rule.ts @@ -121,7 +121,7 @@ * the Perseus article or exercise that is being linted. */ -import {Errors, PerseusError} from "@khanacademy/perseus-error"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import Selector from "./selector"; diff --git a/packages/perseus-linter/src/selector.ts b/packages/perseus-linter/src/selector.ts index c99e9cfa06..34c1150bb9 100644 --- a/packages/perseus-linter/src/selector.ts +++ b/packages/perseus-linter/src/selector.ts @@ -86,7 +86,7 @@ * traversal. */ -import {Errors, PerseusError} from "@khanacademy/perseus-error"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import type {TreeNode, TraversalState} from "./tree-transformer"; diff --git a/packages/perseus-linter/src/tree-transformer.ts b/packages/perseus-linter/src/tree-transformer.ts index f15e57a0e0..8826c64487 100644 --- a/packages/perseus-linter/src/tree-transformer.ts +++ b/packages/perseus-linter/src/tree-transformer.ts @@ -56,7 +56,7 @@ * methods are available to the traversal callback. **/ -import {Errors, PerseusError} from "@khanacademy/perseus-error"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; // TreeNode is the type of a node in a parse tree. The only real requirement is // that every node has a string-valued `type` property diff --git a/packages/perseus-linter/tsconfig-build.json b/packages/perseus-linter/tsconfig-build.json index e6a8a7f342..02a666d614 100644 --- a/packages/perseus-linter/tsconfig-build.json +++ b/packages/perseus-linter/tsconfig-build.json @@ -6,7 +6,6 @@ }, "references": [ {"path": "../perseus-core/tsconfig-build.json"}, - {"path": "../perseus-error/tsconfig-build.json"}, {"path": "../pure-markdown/tsconfig-build.json"}, ] } diff --git a/packages/perseus/src/__tests__/renderer.test.tsx b/packages/perseus/src/__tests__/renderer.test.tsx index eca974ce86..ab3dfd75b2 100644 --- a/packages/perseus/src/__tests__/renderer.test.tsx +++ b/packages/perseus/src/__tests__/renderer.test.tsx @@ -1,4 +1,5 @@ import {describe, beforeAll, beforeEach, it} from "@jest/globals"; +import {Errors} from "@khanacademy/perseus-core"; import {screen, waitFor, within} from "@testing-library/react"; import {userEvent as userEventLib} from "@testing-library/user-event"; import * as React from "react"; @@ -16,7 +17,6 @@ import { mockedShuffledRadioProps, } from "../__testdata__/renderer.testdata"; import * as Dependencies from "../dependencies"; -import {Errors} from "../logging/log"; import {registerWidget} from "../widgets"; import {renderQuestion} from "../widgets/__tests__/renderQuestion"; import InputNumberExport from "../widgets/input-number"; diff --git a/packages/perseus/src/components/graphie-classes.ts b/packages/perseus/src/components/graphie-classes.ts index b53b11e182..350237f25d 100644 --- a/packages/perseus/src/components/graphie-classes.ts +++ b/packages/perseus/src/components/graphie-classes.ts @@ -1,8 +1,8 @@ /* eslint-disable @babel/no-invalid-this */ + +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import _ from "underscore"; -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; import Util from "../util"; const nestedMap = Util.nestedMap; diff --git a/packages/perseus/src/components/graphie.tsx b/packages/perseus/src/components/graphie.tsx index 423c4ae072..ff77591665 100644 --- a/packages/perseus/src/components/graphie.tsx +++ b/packages/perseus/src/components/graphie.tsx @@ -1,10 +1,11 @@ +import {Errors} from "@khanacademy/perseus-core"; import $ from "jquery"; import * as React from "react"; import ReactDOM from "react-dom"; import _ from "underscore"; import InteractiveUtil from "../interactive2/interactive-util"; -import {Errors, Log} from "../logging/log"; +import {Log} from "../logging/log"; import Util from "../util"; import GraphUtils from "../util/graph-utils"; import {Graphie as GraphieDrawingContext} from "../util/graphie"; diff --git a/packages/perseus/src/components/highlighting/highlights.ts b/packages/perseus/src/components/highlighting/highlights.ts index 8b8cc177c5..354eeacc21 100644 --- a/packages/perseus/src/components/highlighting/highlights.ts +++ b/packages/perseus/src/components/highlighting/highlights.ts @@ -2,8 +2,7 @@ * Utility functions for manipulating highlights. */ -import {Errors} from "../../logging/log"; -import {PerseusError} from "../../perseus-error"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import { findFirstAndLastWordIndexes, diff --git a/packages/perseus/src/components/highlighting/word-indexer.tsx b/packages/perseus/src/components/highlighting/word-indexer.tsx index 48ac46e002..63aa4a13b7 100644 --- a/packages/perseus/src/components/highlighting/word-indexer.tsx +++ b/packages/perseus/src/components/highlighting/word-indexer.tsx @@ -11,10 +11,9 @@ * The words yielded by WordIndexer are sorted in document order, which makes * them amenable to binary search - see `findBoundaryWordIndex` in ranges.js. */ -import * as React from "react"; -import {Errors} from "../../logging/log"; -import {PerseusError} from "../../perseus-error"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; +import * as React from "react"; import type {DOMRange} from "./types"; diff --git a/packages/perseus/src/components/prop-check-box.tsx b/packages/perseus/src/components/prop-check-box.tsx index cc0b235f01..13380aef6d 100644 --- a/packages/perseus/src/components/prop-check-box.tsx +++ b/packages/perseus/src/components/prop-check-box.tsx @@ -1,5 +1,6 @@ /* eslint-disable @babel/no-invalid-this */ /* eslint-disable react/sort-comp */ +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import {Checkbox} from "@khanacademy/wonder-blocks-form"; import {LabelSmall} from "@khanacademy/wonder-blocks-typography"; import {css, StyleSheet} from "aphrodite"; @@ -8,9 +9,6 @@ import PropTypes from "prop-types"; import * as React from "react"; import _ from "underscore"; -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; - /* A checkbox that syncs its value to props using the * renderer's onChange method, and gets the prop name * dynamically from its props list diff --git a/packages/perseus/src/components/svg-image.tsx b/packages/perseus/src/components/svg-image.tsx index 161e74e967..40093e2806 100644 --- a/packages/perseus/src/components/svg-image.tsx +++ b/packages/perseus/src/components/svg-image.tsx @@ -1,5 +1,6 @@ /* eslint-disable @khanacademy/ts-no-error-suppressions */ /* eslint-disable react/no-unsafe */ +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import {CircularSpinner} from "@khanacademy/wonder-blocks-progress-spinner"; import classNames from "classnames"; import $ from "jquery"; @@ -7,8 +8,7 @@ import * as React from "react"; import _ from "underscore"; import {getDependencies} from "../dependencies"; -import {Errors, Log} from "../logging/log"; -import {PerseusError} from "../perseus-error"; +import {Log} from "../logging/log"; import Util from "../util"; import * as Zoom from "../zoom"; diff --git a/packages/perseus/src/error-boundary.tsx b/packages/perseus/src/error-boundary.tsx index 3306ed5344..9a998bbc7f 100644 --- a/packages/perseus/src/error-boundary.tsx +++ b/packages/perseus/src/error-boundary.tsx @@ -1,6 +1,7 @@ +import {Errors} from "@khanacademy/perseus-core"; import * as React from "react"; -import {Errors, Log} from "./logging/log"; +import {Log} from "./logging/log"; type Props = { children: React.ReactNode; diff --git a/packages/perseus/src/index.ts b/packages/perseus/src/index.ts index 8dccc9cdd1..966999ba1b 100644 --- a/packages/perseus/src/index.ts +++ b/packages/perseus/src/index.ts @@ -53,8 +53,7 @@ export * as globalStyles from "./styles/global-styles"; export * as globalConstants from "./styles/global-constants"; export * as icons from "./icon-paths"; export * as Dependencies from "./dependencies"; -export {Errors, Log} from "./logging/log"; -export {PerseusError} from "./perseus-error"; +export {Log} from "./logging/log"; export {default as JiptParagraphs} from "./jipt-paragraphs"; export {default as KhanMath} from "./util/math"; export {default as LoadingContext} from "./loading-context"; @@ -132,7 +131,7 @@ export {default as WIDGET_PROP_DENYLIST} from "./mixins/widget-prop-denylist"; * Types */ export type {PerseusOptions} from "./init"; -export type {ILogger, LogErrorOptions, ErrorKind} from "./logging/log"; +export type {ILogger, LogErrorOptions} from "./logging/log"; export type {ServerItemRenderer as ServerItemRendererComponent} from "./server-item-renderer"; export type { Alignment, diff --git a/packages/perseus/src/interactive2/interactive-util.ts b/packages/perseus/src/interactive2/interactive-util.ts index 01396a4e17..b73b25097c 100644 --- a/packages/perseus/src/interactive2/interactive-util.ts +++ b/packages/perseus/src/interactive2/interactive-util.ts @@ -2,11 +2,9 @@ * Utility functions for writing Interactive2 movablethings */ +import {PerseusError, Errors} from "@khanacademy/perseus-core"; import _ from "underscore"; -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; - import MovableHelperMethods from "./movable-helper-methods"; /** diff --git a/packages/perseus/src/interactive2/movable-helper-methods.ts b/packages/perseus/src/interactive2/movable-helper-methods.ts index b48bf80f91..a2be23bdc8 100644 --- a/packages/perseus/src/interactive2/movable-helper-methods.ts +++ b/packages/perseus/src/interactive2/movable-helper-methods.ts @@ -8,11 +8,9 @@ */ import {point as kpoint} from "@khanacademy/kmath"; +import {PerseusError, Errors} from "@khanacademy/perseus-core"; import _ from "underscore"; -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; - /* Local helper methods. */ function getKey(eventName: any, id: any) { diff --git a/packages/perseus/src/interactive2/movable-point.tsx b/packages/perseus/src/interactive2/movable-point.tsx index b5f1edcc12..edd03a86ae 100644 --- a/packages/perseus/src/interactive2/movable-point.tsx +++ b/packages/perseus/src/interactive2/movable-point.tsx @@ -50,13 +50,12 @@ * removes the point from graphie */ import {point as kpoint, vector as kvector} from "@khanacademy/kmath"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import * as React from "react"; import _ from "underscore"; import InlineIcon from "../components/inline-icon"; import {iconTrash} from "../icon-paths"; -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; import KhanColors from "../util/colors"; import reactRender from "../util/react-render"; import Tex from "../util/tex"; diff --git a/packages/perseus/src/interactive2/movable.ts b/packages/perseus/src/interactive2/movable.ts index 26ff5f6ff3..0097d305ac 100644 --- a/packages/perseus/src/interactive2/movable.ts +++ b/packages/perseus/src/interactive2/movable.ts @@ -10,12 +10,10 @@ * take appropriate action in onMoveStart, onMove, onMoveEnd */ import {point as kpoint} from "@khanacademy/kmath"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import $ from "jquery"; import _ from "underscore"; -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; - import InteractiveUtil from "./interactive-util"; import type {Constraint, ConstraintCallbacks, Coord} from "./types"; diff --git a/packages/perseus/src/logging/log.test.ts b/packages/perseus/src/logging/log.test.ts index 4b5853baf4..d57430165c 100644 --- a/packages/perseus/src/logging/log.test.ts +++ b/packages/perseus/src/logging/log.test.ts @@ -1,7 +1,9 @@ +import {Errors} from "@khanacademy/perseus-core"; + import {testDependencies} from "../../../../testing/test-dependencies"; import * as Dependencies from "../dependencies"; -import {Errors, Log} from "./log"; +import {Log} from "./log"; describe("Perseus logging", () => { it("should proxy log() calls to the logger obtained from getDependencies", () => { diff --git a/packages/perseus/src/logging/log.ts b/packages/perseus/src/logging/log.ts index 53dc11bc86..235708d64c 100644 --- a/packages/perseus/src/logging/log.ts +++ b/packages/perseus/src/logging/log.ts @@ -1,54 +1,12 @@ import {getDependencies} from "../dependencies"; +import type {ErrorKind} from "@khanacademy/perseus-core"; import type {Metadata} from "@khanacademy/wonder-stuff-core"; // TODO(LP-11481): Change the primary API we use for logging in Perseus to use // getDependencies() internally... simplify usage to just using a "singleton" // which get's the injected logger. -/** - * @typedef {Object} Errors utility for referencing the Perseus error taxonomy. - */ -export const Errors = Object.freeze({ - /** - * @property {ErrorKind} Unknown The kind of error is not known. - */ - Unknown: "Unknown", - /** - * @property {ErrorKind} Internal The error is internal to the executing code. - */ - Internal: "Internal", - /** - * @property {ErrorKind} InvalidInput There was a problem with the provided - * input, such as the wrong format or a null value. - */ - InvalidInput: "InvalidInput", - /** - * @property {ErrorKind} NotAllowed There was a problem due to the state of - * the system not matching the requested operation or input. For example, - * trying to create a username that is valid, but is already taken by - * another user. Use {@link InvalidInput} instead when the input isn't - * valid regardless of the state of the system. Use {@link NotFound} when - * the failure is due to not being able to find a resource. - */ - NotAllowed: "NotAllowed", - /** - * @property {ErrorKind} TransientService There was a problem when making a - * request to a service. - */ - TransientService: "TransientService", - /** - * @property {ErrorKind} Service There was a non-transient problem when - * making a request to service. - */ - Service: "Service", -}); - -/** - * @type {ErrorKind} The kind of error being reported - */ -export type ErrorKind = (typeof Errors)[keyof typeof Errors]; - export type LogErrorOptions = { // The cause of the error. cause?: Error | null | undefined; diff --git a/packages/perseus/src/mixins/changeable.ts b/packages/perseus/src/mixins/changeable.ts index 92289a72e6..1421500c65 100644 --- a/packages/perseus/src/mixins/changeable.ts +++ b/packages/perseus/src/mixins/changeable.ts @@ -8,12 +8,10 @@ * this.props.onChange with the modified props. */ +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import PropTypes from "prop-types"; import _ from "underscore"; -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; - import WIDGET_PROP_DENYLIST from "./widget-prop-denylist"; import type {ChangeFn} from "../types"; diff --git a/packages/perseus/src/multi-items/items.ts b/packages/perseus/src/multi-items/items.ts index 78d14d6386..5666101a73 100644 --- a/packages/perseus/src/multi-items/items.ts +++ b/packages/perseus/src/multi-items/items.ts @@ -7,8 +7,7 @@ * renderer tree or a score tree or, well, a multi-item), see trees.js. */ -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import shapes from "./shapes"; import {buildMapper} from "./trees"; diff --git a/packages/perseus/src/multi-items/multi-renderer.tsx b/packages/perseus/src/multi-items/multi-renderer.tsx index a5f33132d7..f20f5f6615 100644 --- a/packages/perseus/src/multi-items/multi-renderer.tsx +++ b/packages/perseus/src/multi-items/multi-renderer.tsx @@ -36,6 +36,7 @@ * } * */ +import {Errors} from "@khanacademy/perseus-core"; import {StyleSheet, css} from "aphrodite"; // eslint-disable-line import/no-extraneous-dependencies import lens from "hubble"; // eslint-disable-line import/no-extraneous-dependencies import * as React from "react"; @@ -43,7 +44,7 @@ import * as React from "react"; import {PerseusI18nContext} from "../components/i18n-context"; import {DependenciesContext} from "../dependencies"; import HintsRenderer from "../hints-renderer"; -import {Errors, Log} from "../logging/log"; +import {Log} from "../logging/log"; import Renderer from "../renderer"; import Util from "../util"; diff --git a/packages/perseus/src/multi-items/prop-type-builders.ts b/packages/perseus/src/multi-items/prop-type-builders.ts index fbbb839ae8..7c3d7d2e7a 100644 --- a/packages/perseus/src/multi-items/prop-type-builders.ts +++ b/packages/perseus/src/multi-items/prop-type-builders.ts @@ -6,11 +6,9 @@ */ /* instanbul ignore file */ +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import PropTypes from "prop-types"; -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; - import type {Shape} from "./shape-types"; /** diff --git a/packages/perseus/src/multi-items/trees.ts b/packages/perseus/src/multi-items/trees.ts index e44702c976..6ef124139c 100644 --- a/packages/perseus/src/multi-items/trees.ts +++ b/packages/perseus/src/multi-items/trees.ts @@ -45,8 +45,7 @@ * signatures specified here. */ -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import type { Shape, diff --git a/packages/perseus/src/renderability.ts b/packages/perseus/src/renderability.ts index 35b3014b0d..2cda9a0b22 100644 --- a/packages/perseus/src/renderability.ts +++ b/packages/perseus/src/renderability.ts @@ -8,11 +8,10 @@ * group or sequence widgets. */ +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import _ from "underscore"; -import {Errors} from "./logging/log"; import MultiItems from "./multi-items"; -import {PerseusError} from "./perseus-error"; import {traverse} from "./traversal"; import * as Widgets from "./widgets"; diff --git a/packages/perseus/src/renderer.tsx b/packages/perseus/src/renderer.tsx index 0e14dad4c0..ad02568c8f 100644 --- a/packages/perseus/src/renderer.tsx +++ b/packages/perseus/src/renderer.tsx @@ -1,5 +1,6 @@ /* eslint-disable @khanacademy/ts-no-error-suppressions */ /* eslint-disable react/no-unsafe */ +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import * as PerseusLinter from "@khanacademy/perseus-linter"; import {entries} from "@khanacademy/wonder-stuff-core"; import classNames from "classnames"; @@ -19,9 +20,8 @@ import ErrorBoundary from "./error-boundary"; import InteractionTracker from "./interaction-tracker"; import Objective from "./interactive2/objective_"; import JiptParagraphs from "./jipt-paragraphs"; -import {Errors, Log} from "./logging/log"; +import {Log} from "./logging/log"; import {ClassNames as ApiClassNames, ApiOptions} from "./perseus-api"; -import {PerseusError} from "./perseus-error"; import PerseusMarkdown from "./perseus-markdown"; import QuestionParagraph from "./question-paragraph"; import TranslationLinter from "./translation-linter"; diff --git a/packages/perseus/src/util.ts b/packages/perseus/src/util.ts index ee627b7a7f..bc5408e2d2 100644 --- a/packages/perseus/src/util.ts +++ b/packages/perseus/src/util.ts @@ -1,8 +1,7 @@ /* eslint-disable @babel/no-invalid-this, getter-return, one-var */ +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import _ from "underscore"; -import {Errors} from "./logging/log"; -import {PerseusError} from "./perseus-error"; import KhanAnswerTypes from "./util/answer-types"; import * as GraphieUtil from "./util.graphie"; diff --git a/packages/perseus/src/util/answer-types.ts b/packages/perseus/src/util/answer-types.ts index 3d3c7bdf39..a9450e4217 100644 --- a/packages/perseus/src/util/answer-types.ts +++ b/packages/perseus/src/util/answer-types.ts @@ -1,11 +1,9 @@ /* eslint-disable no-useless-escape */ import * as KAS from "@khanacademy/kas"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import $ from "jquery"; import _ from "underscore"; -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; - import KhanMath from "./math"; import type {PerseusStrings} from "../strings"; diff --git a/packages/perseus/src/util/graphie.ts b/packages/perseus/src/util/graphie.ts index b6914847e1..a68d221521 100644 --- a/packages/perseus/src/util/graphie.ts +++ b/packages/perseus/src/util/graphie.ts @@ -4,6 +4,7 @@ import { vector as kvector, number as knumber, } from "@khanacademy/kmath"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import {entries} from "@khanacademy/wonder-stuff-core"; import $ from "jquery"; // eslint-disable-next-line import/no-extraneous-dependencies @@ -13,8 +14,7 @@ import Raphael from "raphael"; // release // http://groups.google.com/group/raphaeljs/browse_thread/thread/c34c75ad8d431544 -import {Errors, Log} from "../logging/log"; -import {PerseusError} from "../perseus-error"; +import {Log} from "../logging/log"; import KhanColors from "./colors"; import {DrawingTransform} from "./drawing-transform"; diff --git a/packages/perseus/src/util/interactive.ts b/packages/perseus/src/util/interactive.ts index 23ec2b2b7a..605a6bbb0f 100644 --- a/packages/perseus/src/util/interactive.ts +++ b/packages/perseus/src/util/interactive.ts @@ -13,6 +13,7 @@ import { point as kpoint, line as kline, } from "@khanacademy/kmath"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import $ from "jquery"; import _ from "underscore"; @@ -24,8 +25,6 @@ import "../jquery.mobile.vmouse"; import {Arrowhead} from "../interactive2/arrowhead"; import WrappedEllipse from "../interactive2/wrapped-ellipse"; import WrappedLine from "../interactive2/wrapped-line"; -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; import KhanColors from "./colors"; import {clockwise, reverseVector} from "./geometry"; diff --git a/packages/perseus/src/widgets.ts b/packages/perseus/src/widgets.ts index 4ee03d6069..615c1dc37b 100644 --- a/packages/perseus/src/widgets.ts +++ b/packages/perseus/src/widgets.ts @@ -1,7 +1,7 @@ +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import _ from "underscore"; -import {Errors, Log} from "./logging/log"; -import {PerseusError} from "./perseus-error"; +import {Log} from "./logging/log"; import type {PerseusWidget} from "./perseus-types"; import type {PerseusStrings} from "./strings"; diff --git a/packages/perseus/src/widgets/expression.tsx b/packages/perseus/src/widgets/expression.tsx index 8318ae7097..a426009aa5 100644 --- a/packages/perseus/src/widgets/expression.tsx +++ b/packages/perseus/src/widgets/expression.tsx @@ -1,5 +1,6 @@ import * as KAS from "@khanacademy/kas"; import {KeyArray, KeypadInput, KeypadType} from "@khanacademy/math-input"; +import {Errors} from "@khanacademy/perseus-core"; import {linterContextDefault} from "@khanacademy/perseus-linter"; import {View} from "@khanacademy/wonder-blocks-core"; import Tooltip from "@khanacademy/wonder-blocks-tooltip"; @@ -10,7 +11,7 @@ import _ from "underscore"; import {PerseusI18nContext} from "../components/i18n-context"; import MathInput from "../components/math-input"; import {useDependencies} from "../dependencies"; -import {Errors as PerseusErrors, Log} from "../logging/log"; +import {Log} from "../logging/log"; import * as Changeable from "../mixins/changeable"; import {ApiOptions, ClassNames as ApiClassNames} from "../perseus-api"; import a11y from "../util/a11y"; @@ -194,7 +195,7 @@ export class Expression extends React.Component { /* c8 ignore next */ Log.error( "Unable to parse solution answer for expression", - PerseusErrors.InvalidInput, + Errors.InvalidInput, {loggedMetadata: {rubric: JSON.stringify(rubric)}}, ); return null; diff --git a/packages/perseus/src/widgets/interactive-graph.tsx b/packages/perseus/src/widgets/interactive-graph.tsx index 39101f4c4f..93f1532511 100644 --- a/packages/perseus/src/widgets/interactive-graph.tsx +++ b/packages/perseus/src/widgets/interactive-graph.tsx @@ -1,5 +1,6 @@ /* eslint-disable @babel/no-invalid-this, react/no-unsafe, react/sort-comp */ import {number as knumber, point as kpoint} from "@khanacademy/kmath"; +import {Errors, PerseusError} from "@khanacademy/perseus-core"; import $ from "jquery"; import debounce from "lodash.debounce"; import * as React from "react"; @@ -9,8 +10,6 @@ import Graph from "../components/graph"; import {PerseusI18nContext} from "../components/i18n-context"; import Interactive2 from "../interactive2"; import WrappedLine from "../interactive2/wrapped-line"; -import {Errors} from "../logging/log"; -import {PerseusError} from "../perseus-error"; import Util from "../util"; import KhanColors from "../util/colors"; import { diff --git a/packages/perseus/src/widgets/orderer.tsx b/packages/perseus/src/widgets/orderer.tsx index 1fe0e51ce6..e8a9f5784d 100644 --- a/packages/perseus/src/widgets/orderer.tsx +++ b/packages/perseus/src/widgets/orderer.tsx @@ -1,5 +1,6 @@ /* eslint-disable @khanacademy/ts-no-error-suppressions */ /* eslint-disable @babel/no-invalid-this, @typescript-eslint/no-unused-vars, one-var, react/no-unsafe, react/sort-comp */ +import {Errors} from "@khanacademy/perseus-core"; import { linterContextProps, linterContextDefault, @@ -12,7 +13,7 @@ import _ from "underscore"; import {PerseusI18nContext} from "../components/i18n-context"; import {getDependencies} from "../dependencies"; -import {Errors, Log} from "../logging/log"; +import {Log} from "../logging/log"; import {ClassNames as ApiClassNames} from "../perseus-api"; import Renderer from "../renderer"; import Util from "../util"; diff --git a/packages/pure-markdown/package.json b/packages/pure-markdown/package.json index ee1368e30d..3aea8104d4 100644 --- a/packages/pure-markdown/package.json +++ b/packages/pure-markdown/package.json @@ -26,7 +26,6 @@ }, "dependencies": { "@khanacademy/perseus-core": "1.4.2", - "@khanacademy/perseus-error": "^0.3.0", "@khanacademy/simple-markdown": "^0.12.0" }, "devDependencies": {}, diff --git a/packages/pure-markdown/tsconfig-build.json b/packages/pure-markdown/tsconfig-build.json index 7730404faa..69832770b7 100644 --- a/packages/pure-markdown/tsconfig-build.json +++ b/packages/pure-markdown/tsconfig-build.json @@ -6,7 +6,6 @@ }, "references": [ {"path": "../perseus-core/tsconfig-build.json"}, - {"path": "../perseus-error/tsconfig-build.json"}, {"path": "../simple-markdown/tsconfig-build.json"}, ] } diff --git a/tsconfig-build.json b/tsconfig-build.json index 480f8324ec..1ce56e62c6 100644 --- a/tsconfig-build.json +++ b/tsconfig-build.json @@ -11,7 +11,6 @@ {"path": "./packages/perseus/tsconfig-build.json"}, {"path": "./packages/perseus-core/tsconfig-build.json"}, {"path": "./packages/perseus-editor/tsconfig-build.json"}, - {"path": "./packages/perseus-error/tsconfig-build.json"}, {"path": "./packages/perseus-linter/tsconfig-build.json"}, {"path": "./packages/pure-markdown/tsconfig-build.json"}, {"path": "./packages/simple-markdown/tsconfig-build.json"},