Skip to content

Search-TssSecret emits empty typed array on API error — caller cannot distinguish failure from zero results #477

Description

@jagger

Summary

File: src/functions/secrets/Search-TssSecret.ps1:277-298

The 0.62.1 always-array contract emits [Thycotic.PowerShell.Secrets.Summary[]]@() from the else branch when \$restResponse.records is falsy. That branch is reached in two cases:

  1. The API returned successfully with zero records.
  2. The API call threw (caught at line 280) and \$restResponse is \$null.

A caller assigning \[Summary[]\] \$x = Search-TssSecret … receives an empty typed array in both cases and cannot tell which happened. A Write-Warning 'Issue on search request' is emitted in the catch, so a caller using -WarningAction Stop or checking the warning stream is protected — but a caller relying on the result value alone will silently treat an API failure as "no matches."

Proposed fix

Either:

  • On the catch (line 280-284), return after . $ErrorHandling $err so no output is emitted, OR
  • Set a \$hadError flag on catch and skip the else-branch emission on error.

Prefer the second so -ErrorAction Continue callers still see the warning without also getting a misleading empty-array value.

Discovery

Consolidated PR review of v0.62.0 → dev (0.62.1 candidate). Direct consequence of the #459 always-array contract (PR #460); the pre-0.62.1 behavior returned \$null on error, which was equally ambiguous but at least distinguishable by type check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions