Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR at line 1: Unknown command '\-'. When trying to import with - #254

Closed
nextgenthemes opened this issue May 21, 2024 · 6 comments
Closed

Comments

@nextgenthemes
Copy link

Bug Report

Describe the current, buggy behavior

I have been using this command in a script for years. No idea WTF is happening, I need to - to pipe a local file to the remote.

wp @dev db import - < /tmp/ngt.sql
ERROR at line 1: Unknown command '\-'.

Export works perfectly fine wp @prod db export - > "$sql_file"

Describe what you would expect as the correct outcome

No error, like it always did.

Let us know what environment you are running this on

OS:	Linux 5.15.0-83-generic #92-Ubuntu SMP Mon Aug 14 09:30:42 UTC 2023 x86_64
Shell:	/bin/bash
PHP binary:	/usr/bin/php8.1
PHP version:	8.1.27
php.ini used:	/etc/php/8.1/cli/php.ini
MySQL binary:	/usr/bin/mysql
MySQL version:	mysql  Ver 15.1 Distrib 10.6.17-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper
SQL modes:	
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/home/vagrant
WP-CLI packages dir:	
WP-CLI cache dir:	/home/vagrant/.wp-cli/cache
WP-CLI global config:	
WP-CLI project config:	
WP-CLI version:	2.9.0
@nextgenthemes
Copy link
Author

Downgrading to 2.8.1 on all 3 sides did not help. What file? It's not by bash script, as the same error appears when I run this run console.

If this is an error from WP-CLI it would for sure be helpful to know what file this is referring to.

@nextgenthemes
Copy link
Author

cat /tmp/ngt.sql | wp @dev db import - same error.

@mrsdizzie
Copy link
Contributor

That error comes from MySQL / MariaDB itself and indicates an issue with the .sql file.

Since there are two servers involved and there is only version info for one of them, I'm not sure but this recent bug might be relevant if you are exporting from a newer version into an older one: https://jira.mariadb.org/browse/MDEV-34183

Otherwise searching for that error message brings up other possibilities.

@nextgenthemes
Copy link
Author

nextgenthemes commented May 24, 2024

@mrsdizzie Thanks so much! Upgrading MariaDB in my VM did the trick.

I figured it something on my end, probably nothing to do with WP-CLI directly.

I made a simple check of the end of the MySQL file, I assume it was/is perfectly fine. Seems it was the bug you mentioned. https://jira.mariadb.org/browse/MDEV-34183

@wp-cli devs if you could please add some kind of hint to error messages coming from mysql. I thought it has something to do with the - in my command in my bash script, like something tried to escape it '\-'.. Yes stupid and makes no sense I know but ... I thought of all kinds of things, but not about MySQL for some reason.

Error messages that say nothing helpful and do not even tell you where they are coming from are a nightmare.

@mrsdizzie
Copy link
Contributor

Often MySQL errors do identify themselves better (or are more obvious) like:
mysql: Error reading file 'UNKNOWN' (Errcode: 5 "Input/output error")
But not always I guess. I looked into it a bit, but capturing this error and using it in a WP_CLI::error would first involve changing this line:

private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $interactive = false ) {

so $send_to_shell is false. Otherwise it will directly exit here:
https://github.com/wp-cli/wp-cli/blob/f701f406aa39f6aeca2af16e92712780e2675bad/php/utils.php#L587-L589

That of course will also change existing output which would be a breaking change etc... A less breaking option would be to add a WP_CLI::debug call before that exit with more details, though it would still require running with the --debug flag to see what happened.

@danielbachhuber
Copy link
Member

I think we'll refrain from the breaking change for now. We can revisit in the future if it comes up again.

Thanks for the report, @nextgenthemes !

@danielbachhuber danielbachhuber closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants