Skip to content

Commit

Permalink
add PerseusError to perseus-core (#1411)
Browse files Browse the repository at this point in the history
* add PerseusError to perseus-core

* remove code

* changeset

* remove more references to perseus-error

* fix type export
  • Loading branch information
handeyeco authored Jul 15, 2024
1 parent 24a7217 commit b0df85a
Show file tree
Hide file tree
Showing 52 changed files with 66 additions and 349 deletions.
8 changes: 8 additions & 0 deletions .changeset/rare-baboons-change.md
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
4 changes: 4 additions & 0 deletions packages/perseus-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
9 changes: 2 additions & 7 deletions packages/perseus-editor/src/article-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
3 changes: 1 addition & 2 deletions packages/perseus-editor/src/editor.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-editor/src/widgets/cs-program-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
12 changes: 0 additions & 12 deletions packages/perseus-error/.eslintrc.js

This file was deleted.

128 changes: 0 additions & 128 deletions packages/perseus-error/CHANGELOG.md

This file was deleted.

5 changes: 0 additions & 5 deletions packages/perseus-error/README.md

This file was deleted.

37 changes: 0 additions & 37 deletions packages/perseus-error/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/perseus-error/src/version.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/perseus-error/tsconfig-build.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/perseus-error/types

This file was deleted.

3 changes: 1 addition & 2 deletions packages/perseus-linter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-linter/src/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-linter/src/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-linter/src/tree-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion packages/perseus-linter/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
},
"references": [
{"path": "../perseus-core/tsconfig-build.json"},
{"path": "../perseus-error/tsconfig-build.json"},
{"path": "../pure-markdown/tsconfig-build.json"},
]
}
2 changes: 1 addition & 1 deletion packages/perseus/src/__tests__/renderer.test.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus/src/components/graphie-classes.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/perseus/src/components/graphie.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Loading

0 comments on commit b0df85a

Please sign in to comment.