Skip to main content

validate_alias

Function validate_alias 

Source
pub fn validate_alias(alias: &str) -> Result<(), McpError>
Expand description

Validate a user-supplied alias. Must match [A-Za-z_][A-Za-z0-9_]{0,62} and must not equal LOCAL_ALIAS. The 63-char cap matches the PostgreSQL identifier limit Hyper inherits.

§Errors

Returns ErrorCode::InvalidArgument when:

  • alias equals LOCAL_ALIAS (case-insensitive).
  • alias is empty or longer than 63 characters.
  • The first character is neither an ASCII letter nor an underscore.
  • Any subsequent character is outside [A-Za-z0-9_].

Validation does NOT lowercase the alias — error messages preserve the user-typed casing. AttachRegistry::attach canonicalizes the alias to lowercase before storing it, so all downstream lookups (registry, catalog presence cache, qualified SQL identifier) agree on a single form.

§Panics

Does not panic in practice. The chars.next().unwrap() is guarded by the preceding empty-string check, so at least one character is guaranteed to exist.