CLI Export Failures That Look Like Success
In this article
If you exported 11 years of notes through a command-line interface and three failures looked like success, the most likely explanation is that the CLI returned a zero exit code and printed no error output even though the export was incomplete, corrupted, or written to the wrong location. This happens because many CLI tools treat "no crash" as "success" and only signal errors through non-zero exit codes or stderr messages that you may have missed. Below, we break down why this occurs, how to verify an export actually succeeded, and how to avoid silent data loss in the future.
Background: Why CLIs Fail Silently
Command-line tools have a long tradition of using exit codes to communicate success or failure. A zero exit code means "the program ran to completion without a fatal error," but it does not guarantee that the output is correct, complete, or even non-empty. Many tools, especially older ones or those that prioritize speed, will happily exit zero even if they encountered non-fatal issues like skipped files, encoding problems, or disk-full conditions that were caught and ignored.
For example, a note export script might loop through your notes, write each one to a file, and if a file is locked or unreadable, it may simply skip it and continue. If the script doesn't explicitly track skipped items, it will finish with exit code 0 and no error message. You, the user, see a folder full of files and assume everything worked—when in reality, a handful of notes are missing.
How Export Tools Signal Success
To understand why failures look like success, you need to know the three main channels a CLI uses to communicate results:
- Exit code: A number returned to the shell. Zero usually means success, non-zero means failure. But some tools always return zero unless they crash hard.
- Standard output (stdout): The main output stream. This is where the exported data or a progress log goes. If the tool prints "Done!" but the data is truncated, you won't know.
- Standard error (stderr): The stream for error messages. Many tools only write here for fatal errors, so non-fatal issues go unnoticed.
Some tools also write a log file or a manifest. If you don't check that manifest, you might miss warnings. The key is that success is not the absence of an error message; it's the presence of a verified, complete output.
Common Scenarios Where Failures Look Like Success
Here are three concrete situations that match your experience:
- Truncated output due to disk full: The export writes files until the disk is full. The tool catches the write error, stops writing, but returns exit code 0 because it thinks it finished. You see a partial export.
- Missing files due to permission errors: Some notes are in directories you don't have read access to. The tool skips them silently, exports the rest, and exits 0. You get a folder with fewer files than expected.
- Encoding issues: Notes with special characters (like emoji or non-UTF8 characters) cause the exporter to skip or mangle those notes. The tool doesn't report the issue because it's treating it as a non-fatal warning that goes to a log you didn't read.
In all three cases, the CLI looks like it succeeded because it didn't crash and printed a normal completion message. But the output is incomplete or corrupted.
How to Verify an Export Truly Succeeded
To avoid this in the future, you need to add verification steps to your export workflow. Here's a checklist:
- Check the exit code explicitly: In a shell script, use
if [ $? -ne 0 ]; then echo "FAIL"; fiafter the command. But remember, a zero exit code isn't enough. - Compare file counts: If you know how many notes you have, compare that to the number of files exported. Use
find . -type f | wc -lon the export folder. - Check file sizes: If a note is expected to be a few KB, a zero-byte file is a red flag. Use
find . -type f -size 0to find empty files. - Look at the log file: If the tool supports verbose logging, enable it. Then grep the log for "error", "warning", "skip", or "fail".
- Spot-check content: Open a few random files and verify they contain the expected text. This catches silent corruption.
- Re-run the export to a different location: If the export is deterministic, you can export twice and compare checksums. Use
diff -r export1 export2to see if they match.
Common Problems and Misconceptions
One common misconception is that if the CLI doesn't print an error, the export is fine. This is false. Many tools only print errors if they can't open a file at all, but they might silently skip files that are locked, unreadable due to permissions, or that have encoding issues.
Another misconception is that a non-zero exit code always means failure. Some tools use non-zero exit codes for warnings or partial success. For example, a tool might return 1 if it encountered warnings but still produced an output. Always read the documentation for the specific tool to understand its exit code semantics.
Another problem is that some CLIs buffer their output, so if the process is killed abruptly (e.g., by a timeout or a system crash), the buffer is lost and you get an empty or partial file, but the process might have already returned a success code. This is more common with large exports.
Alternatives to CLI Exports
If you're dealing with a large, important dataset like 11 years of notes, consider using a more robust export method:
- Graphical user interface (GUI) export: Many note apps have a GUI export that shows a progress bar and error dialogs. This is often more reliable for non-technical users.
- Database dump: If your notes are stored in a database, use a database dump tool (like
pg_dumpormysqldump) that has built-in integrity checks. - Version control: If you export regularly, consider putting your notes in a Git repository. Then you can verify the export by checking that the working tree matches the committed state.
- Cloud sync with versioning: Some cloud services keep version history, so even if an export fails, you can recover from a previous sync.
Safety and Best Practices for Future Exports
To protect your data, follow these best practices:
- Always export to a new folder: Don't overwrite previous exports. Use a timestamp in the folder name.
- Verify the export before deleting the source: Never delete your original notes until you've confirmed the export is complete and readable.
- Use checksums: Generate a checksum (like SHA-256) of the export folder and store it. Later, you can re-run the checksum to verify integrity.
- Test the restore: Try importing the exported files into a fresh instance of your note app. If that works, the export is likely good.
- Read the tool's documentation: Look for a section on exit codes, error handling, and known limitations. Many tools document how they handle edge cases.
Frequently Asked Questions
Why did my CLI export return exit code 0 but the files are incomplete?
Exit code 0 only means the program didn't crash. It doesn't guarantee that every file was written correctly. The tool may have skipped files due to permission issues, disk full conditions, or encoding errors, and it didn't report them because it didn't consider them fatal. Always verify the output by checking file counts and sizes.
How can I check if my export is missing notes?
Compare the number of exported files with the number of notes you have. If you don't know that number, look for a manifest or index file that the export tool might have generated. Alternatively, re-run the export to a different folder and compare the two folders using diff -r or checksums.
What should I do if I've already deleted the original notes and the export is incomplete?
If you have a backup, restore from it. If not, check if your note app has a trash or recycle bin. Some apps keep deleted notes for a period. If you have a cloud sync, check the cloud service's version history. If none of these work, you may need to use file recovery software on the original drive, but that's not guaranteed.
Does a non-zero exit code always mean the export failed?
Not necessarily. Some tools use non-zero exit codes to indicate warnings or partial success. For example, a tool might return 1 if it encountered a few unreadable files but still exported the rest. Always read the tool's documentation to understand its exit code semantics.
Can I trust a CLI export if it doesn't print any error messages?
No. Many CLIs only print errors to stderr for fatal errors. Non-fatal issues like skipped files or encoding problems may be silently ignored. Always verify the output independently, especially for large or important exports.
Is there a way to make the CLI export more verbose so I can see warnings?
Most CLI tools have a --verbose or --debug flag that enables more detailed logging. Check the tool's help page (tool --help) to see if such an option exists. If it does, use it and redirect the output to a log file so you can review it later.