Skip to content

Commit

Permalink
refactor: remove interface
Browse files Browse the repository at this point in the history
  • Loading branch information
paula-stacho committed Feb 5, 2024
1 parent a8cefb8 commit 92f5d28
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { expect } from '../../../testing/chai';
import { render, mount } from '../../../testing/enzyme';

import { ErrorOutput } from './error-output';
import type { CodedError } from '@mongosh/types';

describe('ErrorOutput', function () {
class MongoError extends Error implements CodedError {
class MongoError extends Error {
code: number;
codeName: string;
errorInfo: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/browser-repl/src/components/types/error-output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isShouldReportAsBugError } from '@mongosh/errors';

import { SimpleTypeOutput } from './simple-type-output';
import { Expandable } from '../utils/expandable';
import type { CodedError } from '@mongosh/types';
import type { MongoServerError } from 'mongodb';

interface ErrorOutputProps {
value: any;
Expand All @@ -16,7 +16,7 @@ export class ErrorOutput extends Component<ErrorOutputProps> {
};

renderCollapsed(toggle: () => void): JSX.Element {
const { name, message, codeName } = this.props.value as CodedError;
const { name, message, codeName } = this.props.value as MongoServerError;
const formattedName = name + (codeName ? `[${codeName}]` : '');
return (
<div>
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-repl/src/format-output.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint no-control-regex: 0 */
import type { CodedError } from '@mongosh/types';
import formatRaw from './format-output';
import { expect } from 'chai';

Expand Down Expand Up @@ -157,7 +156,7 @@ for (const colors of [false, true]) {
});

it('returns name, codeName and message - MongoError', function () {
class MongoError extends Error implements CodedError {
class MongoError extends Error {
code: number;
codeName: string;
constructor(
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-repl/src/format-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
CollectionNamesWithTypes,
} from '@mongosh/shell-api';
import { isShouldReportAsBugError } from '@mongosh/errors';
import type { CodedError } from '@mongosh/types';
import { MongoServerError } from 'mongodb';

type EvaluationResult = {
value: any;
Expand Down Expand Up @@ -252,7 +252,7 @@ export function formatError(error: Error, options: FormatOptions): string {
let result = '';
if (error.name) {
result += `\r${clr(error.name, 'mongosh:error', options)}`;
const codeName = (error as CodedError).codeName;
const codeName = (error as MongoServerError).codeName;
if (codeName)
result += `${clr(
`[` + (codeName as string) + `]`,
Expand Down
5 changes: 0 additions & 5 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,3 @@ export type TimingInterface = {
markTime: (category: TimingCategory, label: string) => void;
getTimingData: () => [string, string, number][];
};

export interface CodedError extends Error {
code?: number;
codeName?: string;
}

0 comments on commit 92f5d28

Please sign in to comment.