@@ -4,12 +4,15 @@ import path from 'path-browserify';
44let gotypes = {
55 Body : "*hype.Body" ,
66 Cmd : "*hype.Cmd" ,
7+ CmdError : "hype.CmdError" ,
78 CmdResult : "*hype.CmdResult" ,
89 Element : "*hype.Element" ,
10+ ExecuteError : "hype.ExecuteError" ,
911 FencedCode : "*hype.FencedCode" ,
1012 Figcaption : "*hype.Figcaption" ,
1113 Figure : "*hype.Figure" ,
1214 Heading : "hype.Heading" ,
15+ HypeError : "hype.HypeError" ,
1316 Image : "*hype.Image" ,
1417 Include : "*hype.Include" ,
1518 InlineCode : "*hype.InlineCode" ,
@@ -18,7 +21,9 @@ let gotypes = {
1821 OL : "*hype.OL" ,
1922 Page : "*hype.Page" ,
2023 Paragraph : "*hype.Paragraph" ,
24+ ParseError : "hype.ParseError" ,
2125 Ref : "*hype.Ref" ,
26+ RunError : "clam.RunError" ,
2227 Snippet : "hype.Snippet" ,
2328 SourceCode : "*hype.SourceCode" ,
2429 TD : "*hype.TD" ,
@@ -607,6 +612,37 @@ function newUUID() {
607612 return `heading-${ v4 ( ) } ` ;
608613}
609614
615+ class CmdError {
616+ constructor ( data , parser ) {
617+ this . args = data . args ;
618+ this . env = data . env ;
619+ this . exit = data . exit ;
620+ this . filename = data . filename ;
621+ this . output = data . output ;
622+ this . root = data . root ;
623+ parser = parser || new Parser ( ) ;
624+ this . err = parser . parseError ( data . err ) ;
625+ }
626+ }
627+ // args: [ 'ech', 'Hello World' ],
628+ // env: [
629+ // ],
630+ // err: 'exec: "ech": executable file not found in $PATH',
631+ // exit: -1,
632+ // filename: 'usage.md',
633+ // output: '',
634+ // root: '/Users/markbates/Library/CloudStorage/Dropbox/dev/guides/hypeviewer',
635+ // type: 'hype.CmdError'
636+
637+ class ExecuteError {
638+ constructor ( data , parser ) {
639+ this . filename = data . filename ;
640+ this . root = data . root ;
641+ parser = parser || new Parser ( ) ;
642+ this . err = parser . parseError ( data . err ) ;
643+ }
644+ }
645+
610646class FencedCode extends Element {
611647 constructor ( fc ) {
612648 super ( fc ) ;
@@ -673,6 +709,15 @@ class Page extends Element {
673709 }
674710}
675711
712+ class ParseError {
713+ constructor ( data , parser ) {
714+ this . filename = data . filename ;
715+ this . root = data . root ;
716+ parser = parser || new Parser ( ) ;
717+ this . err = parser . parseError ( data . err ) ;
718+ }
719+ }
720+
676721class Ref extends Element {
677722 constructor ( r ) {
678723 super ( r ) ;
@@ -776,6 +821,22 @@ class Parser {
776821 data . nodes = this . parseNodes ( data . nodes ) ;
777822 return new Document ( data ) ;
778823 }
824+ parseError ( data ) {
825+ switch ( data . type ) {
826+ case gotypes . ExecuteError :
827+ return new ExecuteError ( data , this ) ;
828+ case gotypes . CmdError :
829+ return new CmdError ( data , this ) ;
830+ case gotypes . ParseError :
831+ return new ParseError ( data , this ) ;
832+ default :
833+ if ( data . type === undefined ) {
834+ return data ;
835+ }
836+ console . warn ( "parseError: unknown type: " , data . type ) ;
837+ return data ;
838+ }
839+ }
779840 parseNodes ( nodes = [ ] ) {
780841 let ret = [ ] ;
781842 nodes . forEach ( ( n ) => {
0 commit comments