Skip to content

Commit

Permalink
maor errors
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Feb 16, 2024
1 parent 9d39765 commit 3354c59
Show file tree
Hide file tree
Showing 24 changed files with 424 additions and 6 deletions.
11 changes: 11 additions & 0 deletions dist/cmd_error.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Parser } from "./parser";
export declare class CmdError {
args: string[];
env: string[];
err: any;
exit: number;
filename: string;
output: string;
root: string;
constructor(data: any, parser?: Parser);
}
22 changes: 22 additions & 0 deletions dist/cmd_error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Parser } from "./parser";
export class CmdError {
constructor(data, parser) {
this.args = data.args;
this.env = data.env;
this.exit = data.exit;
this.filename = data.filename;
this.output = data.output;
this.root = data.root;
parser = parser || new Parser();
this.err = parser.parseError(data.err);
}
}
// args: [ 'ech', 'Hello World' ],
// env: [
// ],
// err: 'exec: "ech": executable file not found in $PATH',
// exit: -1,
// filename: 'usage.md',
// output: '',
// root: '/Users/markbates/Library/CloudStorage/Dropbox/dev/guides/hypeviewer',
// type: 'hype.CmdError'
7 changes: 7 additions & 0 deletions dist/execute_error.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Parser } from "./parser";
export declare class ExecuteError {
filename: string;
root: string;
err: any;
constructor(data: any, parser?: Parser);
}
9 changes: 9 additions & 0 deletions dist/execute_error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Parser } from "./parser";
export class ExecuteError {
constructor(data, parser) {
this.filename = data.filename;
this.root = data.root;
parser = parser || new Parser();
this.err = parser.parseError(data.err);
}
}
5 changes: 5 additions & 0 deletions dist/gotypes.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
declare let gotypes: {
Body: string;
Cmd: string;
CmdError: string;
CmdResult: string;
Element: string;
ExecuteError: string;
FencedCode: string;
Figcaption: string;
Figure: string;
Heading: string;
HypeError: string;
Image: string;
Include: string;
InlineCode: string;
Expand All @@ -15,7 +18,9 @@ declare let gotypes: {
OL: string;
Page: string;
Paragraph: string;
ParseError: string;
Ref: string;
RunError: string;
Snippet: string;
SourceCode: string;
TD: string;
Expand Down
5 changes: 5 additions & 0 deletions dist/gotypes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
let gotypes = {
Body: "*hype.Body",
Cmd: "*hype.Cmd",
CmdError: "hype.CmdError",
CmdResult: "*hype.CmdResult",
Element: "*hype.Element",
ExecuteError: "hype.ExecuteError",
FencedCode: "*hype.FencedCode",
Figcaption: "*hype.Figcaption",
Figure: "*hype.Figure",
Heading: "hype.Heading",
HypeError: "hype.HypeError",
Image: "*hype.Image",
Include: "*hype.Include",
InlineCode: "*hype.InlineCode",
Expand All @@ -15,7 +18,9 @@ let gotypes = {
OL: "*hype.OL",
Page: "*hype.Page",
Paragraph: "*hype.Paragraph",
ParseError: "hype.ParseError",
Ref: "*hype.Ref",
RunError: "clam.RunError",
Snippet: "hype.Snippet",
SourceCode: "*hype.SourceCode",
TD: "*hype.TD",
Expand Down
61 changes: 61 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import path from 'path-browserify';
let gotypes = {
Body: "*hype.Body",
Cmd: "*hype.Cmd",
CmdError: "hype.CmdError",
CmdResult: "*hype.CmdResult",
Element: "*hype.Element",
ExecuteError: "hype.ExecuteError",
FencedCode: "*hype.FencedCode",
Figcaption: "*hype.Figcaption",
Figure: "*hype.Figure",
Heading: "hype.Heading",
HypeError: "hype.HypeError",
Image: "*hype.Image",
Include: "*hype.Include",
InlineCode: "*hype.InlineCode",
Expand All @@ -18,7 +21,9 @@ let gotypes = {
OL: "*hype.OL",
Page: "*hype.Page",
Paragraph: "*hype.Paragraph",
ParseError: "hype.ParseError",
Ref: "*hype.Ref",
RunError: "clam.RunError",
Snippet: "hype.Snippet",
SourceCode: "*hype.SourceCode",
TD: "*hype.TD",
Expand Down Expand Up @@ -607,6 +612,37 @@ function newUUID() {
return `heading-${v4()}`;
}

class CmdError {
constructor(data, parser) {
this.args = data.args;
this.env = data.env;
this.exit = data.exit;
this.filename = data.filename;
this.output = data.output;
this.root = data.root;
parser = parser || new Parser();
this.err = parser.parseError(data.err);
}
}
// args: [ 'ech', 'Hello World' ],
// env: [
// ],
// err: 'exec: "ech": executable file not found in $PATH',
// exit: -1,
// filename: 'usage.md',
// output: '',
// root: '/Users/markbates/Library/CloudStorage/Dropbox/dev/guides/hypeviewer',
// type: 'hype.CmdError'

class ExecuteError {
constructor(data, parser) {
this.filename = data.filename;
this.root = data.root;
parser = parser || new Parser();
this.err = parser.parseError(data.err);
}
}

class FencedCode extends Element {
constructor(fc) {
super(fc);
Expand Down Expand Up @@ -673,6 +709,15 @@ class Page extends Element {
}
}

class ParseError {
constructor(data, parser) {
this.filename = data.filename;
this.root = data.root;
parser = parser || new Parser();
this.err = parser.parseError(data.err);
}
}

class Ref extends Element {
constructor(r) {
super(r);
Expand Down Expand Up @@ -776,6 +821,22 @@ class Parser {
data.nodes = this.parseNodes(data.nodes);
return new Document(data);
}
parseError(data) {
switch (data.type) {
case gotypes.ExecuteError:
return new ExecuteError(data, this);
case gotypes.CmdError:
return new CmdError(data, this);
case gotypes.ParseError:
return new ParseError(data, this);
default:
if (data.type === undefined) {
return data;
}
console.warn("parseError: unknown type: ", data.type);
return data;
}
}
parseNodes(nodes = []) {
let ret = [];
nodes.forEach((n) => {
Expand Down
7 changes: 7 additions & 0 deletions dist/parse_error.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Parser } from "./parser";
export declare class ParseError {
filename: string;
root: string;
err: any;
constructor(data: any, parser?: Parser);
}
9 changes: 9 additions & 0 deletions dist/parse_error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Parser } from "./parser";
export class ParseError {
constructor(data, parser) {
this.filename = data.filename;
this.root = data.root;
parser = parser || new Parser();
this.err = parser.parseError(data.err);
}
}
1 change: 1 addition & 0 deletions dist/parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export declare class Parser {
handlers: any;
constructor();
parse(data: any): Document;
parseError(data: any): any;
private parseNodes;
}
21 changes: 20 additions & 1 deletion dist/parser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Document } from "./document";
import { Cmd } from "./cmd";
import { CmdError } from "./cmd_error";
import { CmdResult } from "./cmd_result";
import { Document } from "./document";
import { Element } from "./element";
import { ExecuteError } from "./execute_error";
import { FencedCode } from "./fenced_code";
import { FigCaption } from "./fig_caption";
import { Figure } from "./figure";
Expand All @@ -13,6 +15,7 @@ import { LI } from "./li";
import { Link } from "./link";
import { OL } from "./ol";
import { Page } from "./page";
import { ParseError } from "./parse_error";
import { Ref } from "./ref";
import { Snippet } from "./snippet";
import { SourceCode } from "./source_code";
Expand Down Expand Up @@ -56,6 +59,22 @@ export class Parser {
data.nodes = this.parseNodes(data.nodes);
return new Document(data);
}
parseError(data) {
switch (data.type) {
case gotypes.ExecuteError:
return new ExecuteError(data, this);
case gotypes.CmdError:
return new CmdError(data, this);
case gotypes.ParseError:
return new ParseError(data, this);
default:
if (data.type === undefined) {
return data;
}
console.warn("parseError: unknown type: ", data.type);
return data;
}
}
parseNodes(nodes = []) {
let ret = [];
nodes.forEach((n) => {
Expand Down
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ declare class Parser {
handlers: any;
constructor();
parse(data: any): Document;
parseError(data: any): any;
private parseNodes;
}

Expand Down Expand Up @@ -573,12 +574,15 @@ declare let atoms: {
declare let gotypes: {
Body: string;
Cmd: string;
CmdError: string;
CmdResult: string;
Element: string;
ExecuteError: string;
FencedCode: string;
Figcaption: string;
Figure: string;
Heading: string;
HypeError: string;
Image: string;
Include: string;
InlineCode: string;
Expand All @@ -587,7 +591,9 @@ declare let gotypes: {
OL: string;
Page: string;
Paragraph: string;
ParseError: string;
Ref: string;
RunError: string;
Snippet: string;
SourceCode: string;
TD: string;
Expand Down
4 changes: 2 additions & 2 deletions module.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# HypeJS

asdfasdfa
asdfasdf

<code src="src/document.ts"></code>
<include src="usage.md"></include>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gopherguides/hypejs",
"version": "0.2.3",
"version": "0.2.4",
"author": "Gopher Guides <[email protected]>",
"description": "kA TypeScript/JavaScript client for Hype JSON",
"license": "CC-BY-NC-SA-4.0",
Expand Down
33 changes: 33 additions & 0 deletions src/cmd_error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ParseError } from "./parse_error";
import { Parser } from "./parser";

export class CmdError {
args: string[];
env: string[];
err: any;
exit: number;
filename: string;
output: string;
root: string;

constructor(data: any, parser?: Parser) {
this.args = data.args;
this.env = data.env;
this.exit = data.exit;
this.filename = data.filename;
this.output = data.output;
this.root = data.root;

parser = parser || new Parser();
this.err = parser.parseError(data.err);
}
}
// args: [ 'ech', 'Hello World' ],
// env: [
// ],
// err: 'exec: "ech": executable file not found in $PATH',
// exit: -1,
// filename: 'usage.md',
// output: '',
// root: '/Users/markbates/Library/CloudStorage/Dropbox/dev/guides/hypeviewer',
// type: 'hype.CmdError'
16 changes: 16 additions & 0 deletions src/execute_error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ParseError } from "./parse_error";
import { Parser } from "./parser";

export class ExecuteError {
filename: string;
root: string;
err: any;

constructor(data: any, parser?: Parser) {
this.filename = data.filename;
this.root = data.root;

parser = parser || new Parser();
this.err = parser.parseError(data.err);
}
}
Loading

0 comments on commit 3354c59

Please sign in to comment.