Skip to content
Snippets Groups Projects
Commit a47c1308 authored by Вартан Бабаян's avatar Вартан Бабаян :dart:
Browse files

feat: add ignore-errors flag for admin cli

parent b379edf3
No related branches found
No related tags found
1 merge request!1494Код возврата в picodata connect/admin
Pipeline #58294 failed
......@@ -22,6 +22,8 @@ with the `YY.MINOR.MICRO` scheme.
- String cells are now output without double quotes during SELECT.
- `picodata connect` and `picodata admin` return a non-zero exit code for file inputs with errors.
- `picodata --version` now provides verbose output, including the build type (static or dynamic) and the build configuration (release or debug)
### Configuration
......
......@@ -283,7 +283,8 @@ fn admin_repl(args: args::Admin) -> Result<(), ReplError> {
let raw_response = temp_client.read()?;
let is_terminal = isatty(0).unwrap_or(false);
if !is_terminal && raw_response.contains("parsing error") {
// In error responses, '- null' always appears at the top of the message.
if !is_terminal && !args.ignore_errors && raw_response.contains("- null\n") {
return Err(ReplError::Other(raw_response));
}
......@@ -297,7 +298,6 @@ fn admin_repl(args: args::Admin) -> Result<(), ReplError> {
))
})?
.to_string(),
};
console.write(&formatted);
......
......@@ -537,6 +537,10 @@ pub struct Admin {
#[clap(value_name = "PATH")]
/// Unix socket path to connect.
pub socket_path: String,
#[clap(long = "ignore-errors")]
/// Flag to continue execution despite invalid queries being sent in non-interactive mode.
pub ignore_errors: bool,
}
impl Admin {
......
......@@ -699,6 +699,7 @@ def test_picodata_version(cluster: Cluster):
def test_admin_cli_exit_code(cluster: Cluster):
# Test the exit code for SQL statements with syntax errors
setup_sql = f"{cluster.data_dir}/setup.sql"
with open(setup_sql, "w") as f:
f.write(
......@@ -723,12 +724,66 @@ def test_admin_cli_exit_code(cluster: Cluster):
timeout=CLI_TIMEOUT,
)
assert process.stderr.find("rule parsing error") != -1
assert process.stderr.find("- null\n") != -1
assert process.stderr.find('GRANT_SYNTAX_ERROR READ TABLE TO "alice"') != -1
assert (
process.returncode != 0
), f"Process failed with exit code {process.returncode}\n"
# Test the exit code when a duplicate values error occurs
insert_sql = f"{cluster.data_dir}/insert.sql"
with open(insert_sql, "w") as f:
f.write(
"""
CREATE TABLE ad_warehouse (id INTEGER PRIMARY KEY);
INSERT INTO ad_warehouse VALUES(1);
INSERT INTO ad_warehouse VALUES(1);
"""
)
i2 = cluster.add_instance(wait_online=False)
i2.start()
i2.wait_online()
process = subprocess.run(
[i2.binary_path, "admin", f"{i2.data_dir}/admin.sock"],
stdin=open(insert_sql, "r"),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
timeout=CLI_TIMEOUT,
)
assert process.stderr.find("- null\n") != -1
assert process.stderr.find("transaction: RolledBack") != -1
assert (
process.returncode != 0
), f"Process failed with exit code {process.returncode}\n"
# Test the exit code when attempting to drop non-existent plugins
plugin_sql = f"{cluster.data_dir}/plugin.sql"
with open(plugin_sql, "w") as f:
f.write("DROP PLUGIN weather_cache 0.1.0;")
i3 = cluster.add_instance(wait_online=False)
i3.start()
i3.wait_online()
process = subprocess.run(
[i3.binary_path, "admin", f"{i3.data_dir}/admin.sock"],
stdin=open(plugin_sql, "r"),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
timeout=CLI_TIMEOUT,
)
assert process.stderr.find("- null\n") != -1
assert process.stderr.find("no such plugin") != -1
assert (
process.returncode != 0
), f"Process failed with exit code {process.returncode}\n"
def test_connect_cli_exit_code(cluster: Cluster):
connect_sql = f"{cluster.data_dir}/connect.sql"
......@@ -761,3 +816,34 @@ def test_connect_cli_exit_code(cluster: Cluster):
assert (
process.returncode != 0
), f"Process failed with exit code {process.returncode}\n"
def test_admin_cli_with_ignore_errors(cluster: Cluster):
setup_sql = f"{cluster.data_dir}/setup.sql"
with open(setup_sql, "w") as f:
f.write(
"""
CREATE USER "alice" WITH PASSWORD 'T0psecret';
GRANT_SYNTAX_ERROR READ TABLE TO "alice";
GRANT WRITE TABLE TO "alice";
"""
)
i1 = cluster.add_instance(wait_online=False)
i1.start()
i1.wait_online()
process = subprocess.run(
[i1.binary_path, "admin", f"{i1.data_dir}/admin.sock", "--ignore-errors"],
stdin=open(setup_sql, "r"),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
timeout=CLI_TIMEOUT,
)
assert process.stdout.find("rule parsing error") != -1
assert process.stdout.find('GRANT_SYNTAX_ERROR READ TABLE TO "alice"') != -1
assert (
process.returncode == 0
), f"Process failed with exit code {process.returncode}\n"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment