| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 67b9dda commit 3f5ff8d
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,6 +147,7 @@ const { | |||
| 147 | 147 | ERR_CANNOT_WATCH_SIGINT, | |
| 148 | 148 | ERR_INVALID_REPL_EVAL_CONFIG, | |
| 149 | 149 | ERR_INVALID_REPL_INPUT, | |
| 150 | + ERR_MISSING_ARGS, | ||
| 150 | 151 | ERR_SCRIPT_EXECUTION_INTERRUPTED, | |
| 151 | 152 | }, | |
| 152 | 153 | isErrorStackTraceLimitWritable, | |
@@ -1788,10 +1789,17 @@ function defineDefaultCommands(repl) { | |||
| 1788 | 1789 | help: 'Save all evaluated commands in this REPL session to a file', | |
| 1789 | 1790 | action: function(file) { | |
| 1790 | 1791 | try { | |
| 1792 | + if (file === '') { | ||
| 1793 | + throw new ERR_MISSING_ARGS('file'); | ||
| 1794 | + } | ||
| 1791 | 1795 | fs.writeFileSync(file, ArrayPrototypeJoin(this.lines, '\n')); | |
| 1792 | 1796 | this.output.write(`Session saved to: ${file}\n`); | |
| 1793 | - } catch { | ||
| 1794 | - this.output.write(`Failed to save: ${file}\n`); | ||
| 1797 | + } catch (error) { | ||
| 1798 | + if (error instanceof ERR_MISSING_ARGS) { | ||
| 1799 | + this.output.write(`${error.message}\n`); | ||
| 1800 | + } else { | ||
| 1801 | + this.output.write(`Failed to save: ${file}\n`); | ||
| 1802 | + } | ||
| 1795 | 1803 | } | |
| 1796 | 1804 | this.displayPrompt(); | |
| 1797 | 1805 | }, | |
@@ -1801,6 +1809,9 @@ function defineDefaultCommands(repl) { | |||
| 1801 | 1809 | help: 'Load JS from a file into the REPL session', | |
| 1802 | 1810 | action: function(file) { | |
| 1803 | 1811 | try { | |
| 1812 | + if (file === '') { | ||
| 1813 | + throw new ERR_MISSING_ARGS('file'); | ||
| 1814 | + } | ||
| 1804 | 1815 | const stats = fs.statSync(file); | |
| 1805 | 1816 | if (stats && stats.isFile()) { | |
| 1806 | 1817 | _turnOnEditorMode(this); | |
@@ -1815,8 +1826,12 @@ function defineDefaultCommands(repl) { | |||
| 1815 | 1826 | `Failed to load: ${file} is not a valid file\n`, | |
| 1816 | 1827 | ); | |
| 1817 | 1828 | } | |
| 1818 | - } catch { | ||
| 1819 | - this.output.write(`Failed to load: ${file}\n`); | ||
| 1829 | + } catch (error) { | ||
| 1830 | + if (error instanceof ERR_MISSING_ARGS) { | ||
| 1831 | + this.output.write(`${error.message}\n`); | ||
| 1832 | + } else { | ||
| 1833 | + this.output.write(`Failed to load: ${file}\n`); | ||
| 1834 | + } | ||
| 1820 | 1835 | } | |
| 1821 | 1836 | this.displayPrompt(); | |
| 1822 | 1837 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,6 @@ const common = require('../common'); | |||
| 24 | 24 | const ArrayStream = require('../common/arraystream'); | |
| 25 | 25 | const assert = require('assert'); | |
| 26 | 26 | const fs = require('fs'); | |
| 27 | - | ||
| 28 | 27 | const tmpdir = require('../common/tmpdir'); | |
| 29 | 28 | tmpdir.refresh(); | |
| 30 | 29 | ||
@@ -139,3 +138,27 @@ putIn.run([`.save ${invalidFileName}`]); | |||
| 139 | 138 | assert.strictEqual(fs.readFileSync(saveFileName, 'utf8'), | |
| 140 | 139 | `${cmds.join('\n')}\n`); | |
| 141 | 140 | } | |
| 141 | + | ||
| 142 | + // Check if the file is present when using save | ||
| 143 | + | ||
| 144 | + // Clear the REPL. | ||
| 145 | + putIn.run(['.clear']); | ||
| 146 | + | ||
| 147 | + // Error message when using save without a file | ||
| 148 | + putIn.write = common.mustCall(function(data) { | ||
| 149 | + assert.strictEqual(data, 'The "file" argument must be specified\n'); | ||
| 150 | + putIn.write = () => {}; | ||
| 151 | + }); | ||
| 152 | + putIn.run(['.save']); | ||
| 153 | + | ||
| 154 | + // Check if the file is present when using load | ||
| 155 | + | ||
| 156 | + // Clear the REPL. | ||
| 157 | + putIn.run(['.clear']); | ||
| 158 | + | ||
| 159 | + // Error message when using load without a file | ||
| 160 | + putIn.write = common.mustCall(function(data) { | ||
| 161 | + assert.strictEqual(data, 'The "file" argument must be specified\n'); | ||
| 162 | + putIn.write = () => {}; | ||
| 163 | + }); | ||
| 164 | + putIn.run(['.load']); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments