Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions shortcuts/calendar/calendar_agenda.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"strings"
"time"

"github.com/larksuite/cli/errs"
"github.com/larksuite/cli/internal/output"
"github.com/larksuite/cli/internal/util"
"github.com/larksuite/cli/internal/validate"
Expand All @@ -29,7 +30,7 @@

func fetchInstanceViewRange(ctx context.Context, runtime *common.RuntimeContext, calendarId string, startTime, endTime int64, depth int) ([]map[string]interface{}, error) {
if depth > 10 {
return nil, output.Errorf(output.ExitInternal, "recursion_limit", "too many splits for instance_view")
return nil, errs.NewInternalError(errs.SubtypeUnknown, "too many splits for instance_view")

Check warning on line 33 in shortcuts/calendar/calendar_agenda.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_agenda.go#L33

Added line #L33 was not covered by tests
}
if startTime > endTime {
return nil, nil
Expand All @@ -54,6 +55,7 @@
"start_time": fmt.Sprintf("%d", startTime),
"end_time": fmt.Sprintf("%d", endTime),
}, nil)
// TODO: convert this API-error path to a typed errs.* error (kept on the legacy envelope for now).
err = wrapPredefinedError(err)
if err != nil {
return nil, output.Errorf(output.ExitAPI, "api_error", "API call failed: %s", err)
Expand All @@ -78,6 +80,7 @@
if int(code) == larkErrCalendarTimeRangeExceeded {
mid := startTime + span/2
if mid <= startTime {
// TODO: convert this API-error path to a typed errs.* error (kept on the legacy envelope for now).
return nil, output.Errorf(output.ExitAPI, "api_error", "query failed: time range exceeds 40-day limit, please narrow the range")
}
left, err := fetchInstanceViewRange(ctx, runtime, calendarId, startTime, mid, depth+1)
Expand All @@ -94,6 +97,7 @@
// Error 193104: too many instances -> split
if int(code) == larkErrCalendarTooManyInstances {
if span <= minSplitWindowSeconds {
// TODO: convert this API-error path to a typed errs.* error (kept on the legacy envelope for now).
return nil, output.Errorf(output.ExitAPI, "api_error", "query failed: more than 1000 instances in the time range, please narrow the range")
}
mid := startTime + span/2
Expand All @@ -109,6 +113,7 @@
}

msg, _ := resultMap["msg"].(string)
// TODO: convert this API-error path to a typed errs.* error (kept on the legacy envelope for now).
return nil, output.ErrAPI(int(code), msg, resultMap["error"])
}

Expand Down Expand Up @@ -147,20 +152,20 @@

startTime, err := common.ParseTime(startInput)
if err != nil {
return 0, 0, output.ErrValidation("--start: %v", err)
return 0, 0, errs.NewValidationError(errs.SubtypeInvalidArgument, "--start: %v", err).WithParam("--start")
}
endTime, err := common.ParseTime(endInput, "end")
if err != nil {
return 0, 0, output.ErrValidation("--end: %v", err)
return 0, 0, errs.NewValidationError(errs.SubtypeInvalidArgument, "--end: %v", err).WithParam("--end")

Check warning on line 159 in shortcuts/calendar/calendar_agenda.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_agenda.go#L159

Added line #L159 was not covered by tests
}

startInt, err := strconv.ParseInt(startTime, 10, 64)
if err != nil {
return 0, 0, output.ErrValidation("invalid start time: %v", err)
return 0, 0, errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid start time: %v", err).WithParam("--start")

Check warning on line 164 in shortcuts/calendar/calendar_agenda.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_agenda.go#L164

Added line #L164 was not covered by tests
}
endInt, err := strconv.ParseInt(endTime, 10, 64)
if err != nil {
return 0, 0, output.ErrValidation("invalid end time: %v", err)
return 0, 0, errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid end time: %v", err).WithParam("--end")

Check warning on line 168 in shortcuts/calendar/calendar_agenda.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_agenda.go#L168

Added line #L168 was not covered by tests
}

return startInt, endInt, nil
Expand Down
31 changes: 17 additions & 14 deletions shortcuts/calendar/calendar_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"strings"
"time"

"github.com/larksuite/cli/errs"
"github.com/larksuite/cli/internal/output"
"github.com/larksuite/cli/internal/validate"
"github.com/larksuite/cli/shortcuts/common"
Expand Down Expand Up @@ -60,7 +61,7 @@
case strings.HasPrefix(id, "ou_"):
attendees = append(attendees, map[string]string{"type": "user", "user_id": id})
default:
return nil, fmt.Errorf("unsupported attendee id format: %s", id)
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "unsupported attendee id format: %s", id)

Check warning on line 64 in shortcuts/calendar/calendar_create.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_create.go#L64

Added line #L64 was not covered by tests
}
}
return attendees, nil
Expand Down Expand Up @@ -90,7 +91,7 @@
for _, flag := range []string{"summary", "description", "rrule", "calendar-id"} {
if val := runtime.Str(flag); val != "" {
if err := common.RejectDangerousChars("--"+flag, val); err != nil {
return output.ErrValidation(err.Error())
return errs.NewValidationError(errs.SubtypeInvalidArgument, "%s", err)

Check warning on line 94 in shortcuts/calendar/calendar_create.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_create.go#L94

Added line #L94 was not covered by tests
}
}
}
Expand All @@ -102,35 +103,35 @@
continue
}
if !strings.HasPrefix(id, "ou_") && !strings.HasPrefix(id, "oc_") && !strings.HasPrefix(id, "omm_") {
return output.ErrValidation("invalid attendee id format %q: should start with 'ou_', 'oc_', or 'omm_'", id)
return errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid attendee id format %q: should start with 'ou_', 'oc_', or 'omm_'", id).WithParam("--attendee-ids")
}
}
}

if runtime.Str("start") == "" {
return common.FlagErrorf("specify --start (e.g. '2026-03-12T14:00+08:00')")
return errs.NewValidationError(errs.SubtypeInvalidArgument, "specify --start (e.g. '2026-03-12T14:00+08:00')").WithParam("--start")
}
if runtime.Str("end") == "" {
return common.FlagErrorf("specify --end (e.g. '2026-03-12T15:00+08:00')")
return errs.NewValidationError(errs.SubtypeInvalidArgument, "specify --end (e.g. '2026-03-12T15:00+08:00')").WithParam("--end")

Check warning on line 115 in shortcuts/calendar/calendar_create.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_create.go#L115

Added line #L115 was not covered by tests
}
startTs, err := common.ParseTime(runtime.Str("start"))
if err != nil {
return common.FlagErrorf("--start: %v", err)
return errs.NewValidationError(errs.SubtypeInvalidArgument, "--start: %v", err).WithParam("--start")

Check warning on line 119 in shortcuts/calendar/calendar_create.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_create.go#L119

Added line #L119 was not covered by tests
}
endTs, err := common.ParseTime(runtime.Str("end"), "end")
if err != nil {
return common.FlagErrorf("--end: %v", err)
return errs.NewValidationError(errs.SubtypeInvalidArgument, "--end: %v", err).WithParam("--end")

Check warning on line 123 in shortcuts/calendar/calendar_create.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_create.go#L123

Added line #L123 was not covered by tests
}
s, err := strconv.ParseInt(startTs, 10, 64)
if err != nil {
return common.FlagErrorf("invalid start time: %v", err)
return errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid start time: %v", err).WithParam("--start")

Check warning on line 127 in shortcuts/calendar/calendar_create.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_create.go#L127

Added line #L127 was not covered by tests
}
e, err := strconv.ParseInt(endTs, 10, 64)
if err != nil {
return common.FlagErrorf("invalid end time: %v", err)
return errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid end time: %v", err).WithParam("--end")

Check warning on line 131 in shortcuts/calendar/calendar_create.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_create.go#L131

Added line #L131 was not covered by tests
}
if e <= s {
return common.FlagErrorf("end time must be after start time")
return errs.NewValidationError(errs.SubtypeInvalidArgument, "end time must be after start time")
}
return nil
},
Expand Down Expand Up @@ -183,16 +184,17 @@

startTs, err := common.ParseTime(runtime.Str("start"))
if err != nil {
return output.ErrValidation("--start: %v", err)
return errs.NewValidationError(errs.SubtypeInvalidArgument, "--start: %v", err).WithParam("--start")

Check warning on line 187 in shortcuts/calendar/calendar_create.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_create.go#L187

Added line #L187 was not covered by tests
}
endTs, err := common.ParseTime(runtime.Str("end"), "end")
if err != nil {
return output.ErrValidation("--end: %v", err)
return errs.NewValidationError(errs.SubtypeInvalidArgument, "--end: %v", err).WithParam("--end")

Check warning on line 191 in shortcuts/calendar/calendar_create.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_create.go#L191

Added line #L191 was not covered by tests
}

eventData := buildEventData(runtime, startTs, endTs)

// Create event
// TODO: convert this API-error path to a typed errs.* error (kept on the legacy envelope for now).
data, err := runtime.CallAPI("POST",
fmt.Sprintf("/open-apis/calendar/v4/calendars/%s/events", validate.EncodePathSegment(calendarId)),
nil, eventData)
Expand All @@ -203,7 +205,7 @@
event, _ := data["event"].(map[string]interface{})
eventId, _ := event["event_id"].(string)
if eventId == "" {
return output.Errorf(output.ExitAPI, "api_error", "failed to create event: no event_id returned")
return errs.NewInternalError(errs.SubtypeInvalidResponse, "failed to create event: no event_id returned")
}

// Add attendees if specified
Expand All @@ -214,9 +216,10 @@
}
attendees, err := parseAttendees(attendeesStr, currentUserId)
if err != nil {
return output.ErrValidation("invalid attendee id: %v", err)
return errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid attendee id: %v", err)

Check warning on line 219 in shortcuts/calendar/calendar_create.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_create.go#L219

Added line #L219 was not covered by tests
}
Comment on lines 217 to 220
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Avoid wrapping typed validation errors.

Line 219 wraps the typed *errs.ValidationError returned by parseAttendees (line 64) in a new validation error, which loses the original error's typed structure and creates redundant message nesting ("invalid attendee id: unsupported attendee id format: X").

Return the error directly instead:

 attendees, err := parseAttendees(attendeesStr, currentUserId)
 if err != nil {
-    return errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid attendee id: %v", err)
+    return err
 }

If parameter context is needed, add .WithParam("--attendee-ids") via type assertion or modify parseAttendees to accept the parameter name (see suggestion on lines 39-68).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
attendees, err := parseAttendees(attendeesStr, currentUserId)
if err != nil {
return output.ErrValidation("invalid attendee id: %v", err)
return errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid attendee id: %v", err)
}
attendees, err := parseAttendees(attendeesStr, currentUserId)
if err != nil {
return err
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shortcuts/calendar/calendar_create.go` around lines 217 - 220, The code
currently wraps the typed *errs.ValidationError returned by
parseAttendees(attendeesStr, currentUserId) into a new errs.NewValidationError,
losing the original error type and nesting messages; instead, return the
parseAttendees error directly, and if you need parameter context call
WithParam("--attendee-ids") on the returned error via a type assertion (e.g., if
ve, ok := err.(*errs.ValidationError); ok { return
ve.WithParam("--attendee-ids") } else { return err }), or modify parseAttendees
to accept the parameter name so it can produce a validation error with the param
already set.


// TODO: convert this API-error path to a typed errs.* error (kept on the legacy envelope for now).
_, err = runtime.CallAPI("POST",
fmt.Sprintf("/open-apis/calendar/v4/calendars/%s/events/%s/attendees", validate.EncodePathSegment(calendarId), validate.EncodePathSegment(eventId)),
map[string]interface{}{"user_id_type": "open_id"},
Expand Down
20 changes: 12 additions & 8 deletions shortcuts/calendar/calendar_freebusy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"strconv"
"time"

"github.com/larksuite/cli/errs"
"github.com/larksuite/cli/internal/output"
"github.com/larksuite/cli/shortcuts/common"
)
Expand All @@ -20,20 +21,20 @@

startTs, err := common.ParseTime(startInput)
if err != nil {
return "", "", output.ErrValidation("--start: %v", err)
return "", "", errs.NewValidationError(errs.SubtypeInvalidArgument, "--start: %v", err).WithParam("--start")
}
endTs, err := common.ParseTime(endInput, "end")
if err != nil {
return "", "", output.ErrValidation("--end: %v", err)
return "", "", errs.NewValidationError(errs.SubtypeInvalidArgument, "--end: %v", err).WithParam("--end")

Check warning on line 28 in shortcuts/calendar/calendar_freebusy.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_freebusy.go#L28

Added line #L28 was not covered by tests
}

startSec, err := strconv.ParseInt(startTs, 10, 64)
if err != nil {
return "", "", output.ErrValidation("invalid start timestamp: %v", err)
return "", "", errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid start timestamp: %v", err)

Check warning on line 33 in shortcuts/calendar/calendar_freebusy.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_freebusy.go#L33

Added line #L33 was not covered by tests
}
endSec, err := strconv.ParseInt(endTs, 10, 64)
if err != nil {
return "", "", output.ErrValidation("invalid end timestamp: %v", err)
return "", "", errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid end timestamp: %v", err)

Check warning on line 37 in shortcuts/calendar/calendar_freebusy.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_freebusy.go#L37

Added line #L37 was not covered by tests
}

timeMin := time.Unix(startSec, 0).Format(time.RFC3339)
Expand Down Expand Up @@ -73,14 +74,14 @@
}
userId := runtime.Str("user-id")
if userId == "" && runtime.IsBot() {
return common.FlagErrorf("--user-id is required for bot identity")
return errs.NewValidationError(errs.SubtypeInvalidArgument, "--user-id is required for bot identity").WithParam("--user-id")
}
if userId == "" && runtime.UserOpenId() == "" {
return common.FlagErrorf("cannot determine user ID, specify --user-id or ensure you are logged in")
return errs.NewValidationError(errs.SubtypeInvalidArgument, "cannot determine user ID, specify --user-id or ensure you are logged in").WithParam("--user-id")

Check warning on line 80 in shortcuts/calendar/calendar_freebusy.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_freebusy.go#L80

Added line #L80 was not covered by tests
}
if userId != "" {
if _, err := common.ValidateUserID(userId); err != nil {
return err
return errs.NewValidationError(errs.SubtypeInvalidArgument, "%s", err).WithParam("--user-id")

Check warning on line 84 in shortcuts/calendar/calendar_freebusy.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_freebusy.go#L84

Added line #L84 was not covered by tests
}
}
return nil
Expand All @@ -93,9 +94,12 @@

timeMin, timeMax, err := parseFreebusyTimeRange(runtime)
if err != nil {
return output.ErrValidation("--start/--end: %v", err)
// parseFreebusyTimeRange already returns a typed *errs.ValidationError
// carrying the offending flag in .Param; pass it through unchanged.
return err
}

// TODO: convert this API-error path to a typed errs.* error (kept on the legacy envelope for now).
data, err := runtime.CallAPI("POST", "/open-apis/calendar/v4/freebusy/list", nil, map[string]interface{}{
"time_min": timeMin,
"time_max": timeMax,
Expand Down
43 changes: 24 additions & 19 deletions shortcuts/calendar/calendar_room_find.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"sync"
"time"

"github.com/larksuite/cli/errs"
"github.com/larksuite/cli/internal/errclass"
"github.com/larksuite/cli/internal/output"
"github.com/larksuite/cli/shortcuts/common"
larkcore "github.com/larksuite/oapi-sdk-go/v3/core"
Expand Down Expand Up @@ -126,40 +128,40 @@
func parseRoomFindSlots(runtime *common.RuntimeContext) ([]roomFindSlot, error) {
rawSlots := runtime.StrArray(flagSlot)
if len(rawSlots) == 0 {
return nil, output.ErrValidation("specify at least one --slot")
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "specify at least one --slot").WithParam("--slot")
}
slots := make([]roomFindSlot, 0, len(rawSlots))
for _, raw := range rawSlots {
parts := strings.Split(strings.TrimSpace(raw), "~")
if len(parts) != 2 {
return nil, output.ErrValidation("invalid --slot format %q, expected start~end", raw)
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid --slot format %q, expected start~end", raw).WithParam("--slot")

Check warning on line 137 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L137

Added line #L137 was not covered by tests
}
startTs, err := common.ParseTime(parts[0])
if err != nil {
return nil, output.ErrValidation("invalid slot start time %q: %v", parts[0], err)
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid slot start time %q: %v", parts[0], err).WithParam("--slot")

Check warning on line 141 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L141

Added line #L141 was not covered by tests
}
endTs, err := common.ParseTime(parts[1])
if err != nil {
return nil, output.ErrValidation("invalid slot end time %q: %v", parts[1], err)
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid slot end time %q: %v", parts[1], err).WithParam("--slot")

Check warning on line 145 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L145

Added line #L145 was not covered by tests
}
startSec, err := strconv.ParseInt(startTs, 10, 64)
if err != nil {
return nil, output.ErrValidation("invalid slot start timestamp %q: %v", startTs, err)
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid slot start timestamp %q: %v", startTs, err).WithParam("--slot")

Check warning on line 149 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L149

Added line #L149 was not covered by tests
}
endSec, err := strconv.ParseInt(endTs, 10, 64)
if err != nil {
return nil, output.ErrValidation("invalid slot end timestamp %q: %v", endTs, err)
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid slot end timestamp %q: %v", endTs, err).WithParam("--slot")

Check warning on line 153 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L153

Added line #L153 was not covered by tests
}
if endSec <= startSec {
return nil, output.ErrValidation("--slot end time must be after start time: %q", raw)
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "--slot end time must be after start time: %q", raw).WithParam("--slot")
}
startRFC3339, err := unixStringToRFC3339(startTs)
if err != nil {
return nil, output.ErrValidation("invalid slot start timestamp %q: %v", startTs, err)
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid slot start timestamp %q: %v", startTs, err).WithParam("--slot")

Check warning on line 160 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L160

Added line #L160 was not covered by tests
}
endRFC3339, err := unixStringToRFC3339(endTs)
if err != nil {
return nil, output.ErrValidation("invalid slot end timestamp %q: %v", endTs, err)
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid slot end timestamp %q: %v", endTs, err).WithParam("--slot")

Check warning on line 164 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L164

Added line #L164 was not covered by tests
}
slots = append(slots, roomFindSlot{Start: startRFC3339, End: endRFC3339})
}
Expand Down Expand Up @@ -196,7 +198,7 @@
seenChats[id] = true
}
default:
return nil, nil, output.ErrValidation("invalid attendee id format %q: should start with 'ou_' or 'oc_'", id)
return nil, nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid attendee id format %q: should start with 'ou_' or 'oc_'", id)

Check warning on line 201 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L201

Added line #L201 was not covered by tests
}
}
if currentUserID != "" && !seenUsers[currentUserID] {
Expand Down Expand Up @@ -249,20 +251,23 @@
Body: req,
})
if err != nil {
return nil, err
if _, ok := errs.ProblemOf(err); ok {
return nil, err

Check warning on line 255 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L254-L255

Added lines #L254 - L255 were not covered by tests
}
return nil, errs.WrapInternal(err)

Check warning on line 257 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L257

Added line #L257 was not covered by tests
}

if apiResp.StatusCode < http.StatusOK || apiResp.StatusCode >= http.StatusMultipleChoices {
return nil, output.ErrAPI(apiResp.StatusCode, "", string(apiResp.RawBody))
return nil, errs.NewAPIError(errs.SubtypeUnknown, "%s", string(apiResp.RawBody)).WithCode(apiResp.StatusCode)
}

var resp = &OpenAPIResponse[*roomFindData]{}
if err := json.Unmarshal(apiResp.RawBody, &resp); err != nil {
return nil, output.ErrWithHint(output.ExitInternal, "validation", "unmarshal response fail", err.Error())
return nil, errs.NewInternalError(errs.SubtypeInvalidResponse, "unmarshal response fail").WithCause(err)

Check warning on line 266 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L266

Added line #L266 was not covered by tests
}

if resp.Code != 0 {
return nil, output.ErrAPI(resp.Code, resp.Msg, resp.Data)
return nil, errclass.BuildAPIError(map[string]any{"code": resp.Code, "msg": resp.Msg}, errclass.ClassifyContext{})
}

if resp.Data != nil {
Expand Down Expand Up @@ -318,7 +323,7 @@
for _, flag := range []string{flagCity, flagBuilding, flagFloor, flagEventRrule, flagTimezone} {
if val := strings.TrimSpace(runtime.Str(flag)); val != "" {
if err := common.RejectDangerousChars("--"+flag, val); err != nil {
return output.ErrValidation(err.Error())
return errs.NewValidationError(errs.SubtypeInvalidArgument, "%s", err)

Check warning on line 326 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L326

Added line #L326 was not covered by tests
}
}
}
Expand All @@ -328,7 +333,7 @@
continue
}
if err := common.RejectDangerousChars("--"+flagRoomName, name); err != nil {
return output.ErrValidation(err.Error())
return errs.NewValidationError(errs.SubtypeInvalidArgument, "%s", err)
}
}
if _, err := parseRoomFindSlots(runtime); err != nil {
Expand All @@ -338,13 +343,13 @@
return err
}
if minCapacity := runtime.Int(flagMinCapacity); minCapacity < 0 {
return output.ErrValidation("--min-capacity must be >= 0")
return errs.NewValidationError(errs.SubtypeInvalidArgument, "--min-capacity must be >= 0").WithParam("--min-capacity")

Check warning on line 346 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L346

Added line #L346 was not covered by tests
}
if maxCapacity := runtime.Int(flagMaxCapacity); maxCapacity < 0 {
return output.ErrValidation("--max-capacity must be >= 0")
return errs.NewValidationError(errs.SubtypeInvalidArgument, "--max-capacity must be >= 0").WithParam("--max-capacity")

Check warning on line 349 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L349

Added line #L349 was not covered by tests
}
if minCapacity, maxCapacity := runtime.Int(flagMinCapacity), runtime.Int(flagMaxCapacity); minCapacity > 0 && maxCapacity > 0 && minCapacity > maxCapacity {
return output.ErrValidation("--min-capacity must be <= --max-capacity")
return errs.NewValidationError(errs.SubtypeInvalidArgument, "--min-capacity must be <= --max-capacity").WithParam("--min-capacity")

Check warning on line 352 in shortcuts/calendar/calendar_room_find.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/calendar/calendar_room_find.go#L352

Added line #L352 was not covered by tests
}
return nil
},
Expand Down
Loading
Loading