Skip to content

StylistService.cs: Unsafe array access on OpenAI response Content[0] #95

@AB-Law

Description

@AB-Law

Problem

PluckIt.Infrastructure/StylistService.cs:68 directly accesses result.Content[0].Text without checking if Content is non-empty. If OpenAI returns an empty content array (on refusal or model error) this throws an unhandled IndexOutOfRangeException.

var content = result.Content[0].Text; // throws if Content is empty

Impact

Any stylist recommendation request that receives a non-standard OpenAI response crashes with a 500 and gives the user no actionable message.

Proposed Fix

if (result.Content is not { Count: > 0 })
    throw new InvalidOperationException("OpenAI returned empty content.");
var content = result.Content[0].Text;

Functionality Impact

Converts silent crash to explicit structured error response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions