Commit 93b78ea 1 parent b490b8c commit 93b78ea Copy full SHA for 93b78ea
File tree 2 files changed +22
-3
lines changed
2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 54
54
exp=$(cat tests/double-nested-objects.go)
55
55
echo "got: '${got}'"
56
56
[[ "${got}" == "${exp}" ]]
57
+
58
+ - name : Check correct error handling using stdin
59
+ shell : bash
60
+ run : |
61
+ ! node json-to-go.js <<< "error"
62
+
63
+ - name : Check correct error handling with a file
64
+ shell : bash
65
+ run : |
66
+ ! node json-to-go.js <(echo "error")
Original file line number Diff line number Diff line change @@ -498,6 +498,15 @@ if (typeof module != 'undefined') {
498
498
let bigstdin = false
499
499
let filename = null
500
500
501
+ function jsonToGoWithErrorHandling ( json ) {
502
+ const output = jsonToGo ( json )
503
+ if ( output . error ) {
504
+ console . error ( output . error )
505
+ process . exitCode = 1
506
+ }
507
+ process . stdout . write ( output . go )
508
+ }
509
+
501
510
process . argv . forEach ( ( val , index ) => {
502
511
if ( index < 2 )
503
512
return
@@ -519,7 +528,7 @@ if (typeof module != 'undefined') {
519
528
if ( filename ) {
520
529
const fs = require ( 'fs' ) ;
521
530
const json = fs . readFileSync ( filename , 'utf8' ) ;
522
- process . stdout . write ( jsonToGo ( json ) . go )
531
+ jsonToGoWithErrorHandling ( json )
523
532
return
524
533
}
525
534
@@ -530,15 +539,15 @@ if (typeof module != 'undefined') {
530
539
} )
531
540
process . stdin . on ( 'end' , function ( ) {
532
541
const json = Buffer . concat ( bufs ) . toString ( 'utf8' )
533
- process . stdout . write ( jsonToGo ( json ) . go )
542
+ jsonToGoWithErrorHandling ( json )
534
543
} )
535
544
return
536
545
}
537
546
538
547
// read from stdin
539
548
process . stdin . on ( 'data' , function ( buf ) {
540
549
const json = buf . toString ( 'utf8' )
541
- process . stdout . write ( jsonToGo ( json ) . go )
550
+ jsonToGoWithErrorHandling ( json )
542
551
} )
543
552
} else {
544
553
module . exports = jsonToGo
You can’t perform that action at this time.
0 commit comments