MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / parse_fail_sql

Function parse_fail_sql

src/testdrive/src/parser.rs:418–477  ·  view source on GitHub ↗
(line_reader: &mut LineReader)

Source from the content-addressed store, hash-verified

416}
417
418fn parse_fail_sql(line_reader: &mut LineReader) -> Result<FailSqlCommand, PosError> {
419 let (pos, line1) = line_reader.next().unwrap();
420 let line2 = slurp_one(line_reader);
421 let (err_pos, expected_error) = match line2 {
422 Some((err_pos, line2)) => (err_pos, line2),
423 None => {
424 return Err(PosError {
425 pos: Some(pos),
426 source: anyhow!("failing SQL command is missing expected error message"),
427 });
428 }
429 };
430 let query = line1[1..].trim().to_string();
431
432 let expected_error = if let Some(e) = expected_error.strip_prefix("regex:") {
433 SqlExpectedError::Regex(e.trim().into())
434 } else if let Some(e) = expected_error.strip_prefix("contains:") {
435 SqlExpectedError::Contains(e.trim().into())
436 } else if let Some(e) = expected_error.strip_prefix("exact:") {
437 SqlExpectedError::Exact(e.trim().into())
438 } else if expected_error == "timeout" {
439 SqlExpectedError::Timeout
440 } else {
441 return Err(PosError {
442 pos: Some(err_pos),
443 source: anyhow!(
444 "Query error must start with match specifier (`regex:`|`contains:`|`exact:`|`timeout`)"
445 ),
446 });
447 };
448
449 let extra_error = |line_reader: &mut LineReader, prefix| {
450 if let Some((_pos, line)) = line_reader.peek() {
451 if let Some(_) = line.strip_prefix(prefix) {
452 let line = line_reader
453 .next()
454 .map(|(_, line)| line)
455 .unwrap()
456 .strip_prefix(prefix)
457 .map(|line| line.to_string())
458 .unwrap();
459 Some(line.trim().to_string())
460 } else {
461 None
462 }
463 } else {
464 None
465 }
466 };
467 // Expect `hint` to always follow `detail` if they are both present, for now.
468 let expected_detail = extra_error(line_reader, "detail:");
469 let expected_hint = extra_error(line_reader, "hint:");
470
471 Ok(FailSqlCommand {
472 query: query.trim().to_string(),
473 expected_error,
474 expected_detail,
475 expected_hint,

Callers 1

parseFunction · 0.85

Calls 8

slurp_oneFunction · 0.85
unwrapMethod · 0.80
RegexClass · 0.50
nextMethod · 0.45
to_stringMethod · 0.45
trimMethod · 0.45
peekMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected