@@ -89,8 +89,12 @@ func (f *Fetcher) fetchUsers(ctx context.Context, outputWriter *js.JSONArrayWrit
8989 }
9090
9191 for _ , user := range users {
92- obj , skip := f .buildOutputObjects (ctx , user , errorWriter )
93- if skip {
92+ obj , err := f .buildOutputObjects (ctx , user )
93+ if err != nil {
94+ common .WriteErrorWithExitCode (errorWriter , err , 1 )
95+ }
96+
97+ if obj == nil {
9498 continue
9599 }
96100
@@ -111,42 +115,40 @@ func (f *Fetcher) fetchUsers(ctx context.Context, outputWriter *js.JSONArrayWrit
111115}
112116
113117// return a object map to output or a boolean to skip current user.
114- func (f * Fetcher ) buildOutputObjects (ctx context.Context , user * management.User , errorWriter io. Writer ) (map [string ]any , bool ) {
118+ func (f * Fetcher ) buildOutputObjects (ctx context.Context , user * management.User ) (map [string ]any , error ) {
115119 var obj map [string ]any
116120
117121 res , err := user .MarshalJSON ()
118122 if err != nil {
119- common .WriteErrorWithExitCode (errorWriter , err , 1 )
120- return obj , true
123+ return nil , err
121124 }
122125
123126 if err := json .Unmarshal (res , & obj ); err != nil {
124- common .WriteErrorWithExitCode (errorWriter , err , 1 )
125- return obj , true
127+ return nil , err
126128 }
127129
128130 obj ["email_verified" ] = user .GetEmailVerified ()
129131 obj ["object_type" ] = "user"
130132
131133 if f .Roles {
132- roles , err := f .getUserRoles (ctx , * user .ID )
134+ roles , err := f .fetchUserRoles (ctx , * user .ID )
133135 if err != nil {
134- common . WriteErrorWithExitCode ( errorWriter , err , 1 )
136+ return nil , err
135137 } else {
136138 obj ["roles" ] = roles
137139 }
138140 }
139141
140142 if f .Orgs {
141- orgs , err := f .getOrgs (ctx , * user .ID )
143+ orgs , err := f .fetchOrgs (ctx , * user .ID )
142144 if err != nil {
143- common . WriteErrorWithExitCode ( errorWriter , err , 1 )
145+ return nil , err
144146 } else {
145147 obj ["orgs" ] = orgs
146148 }
147149 }
148150
149- return obj , false
151+ return obj , nil
150152}
151153
152154func (f * Fetcher ) fetchGroups (ctx context.Context , outputWriter * js.JSONArrayWriter , errorWriter io.Writer ) error {
@@ -159,7 +161,7 @@ func (f *Fetcher) fetchGroups(ctx context.Context, outputWriter *js.JSONArrayWri
159161 opts = append (opts , management .Query (f .getConnectionQuery ()))
160162 }
161163
162- roles , more , err := f .getRoles (ctx , opts )
164+ roles , more , err := f .fetchRoles (ctx , opts )
163165 if err != nil {
164166 common .WriteErrorWithExitCode (errorWriter , err , 1 )
165167 return err
@@ -239,7 +241,7 @@ func (f *Fetcher) getUsers(ctx context.Context, opts []management.RequestOption)
239241 return ul .UserList (), ul .HasNext (), nil
240242}
241243
242- func (f * Fetcher ) getRoles (ctx context.Context , opts []management.RequestOption ) ([]* management.Role , bool , error ) {
244+ func (f * Fetcher ) fetchRoles (ctx context.Context , opts []management.RequestOption ) ([]* management.Role , bool , error ) {
243245 roles , err := f .client .Mgmt .Role .List (ctx , opts ... )
244246 if err != nil {
245247 return nil , false , err
@@ -252,7 +254,7 @@ func (f *Fetcher) getRoles(ctx context.Context, opts []management.RequestOption)
252254 return roles .Roles , roles .HasNext (), nil
253255}
254256
255- func (f * Fetcher ) getUserRoles (ctx context.Context , uID string ) ([]map [string ]any , error ) {
257+ func (f * Fetcher ) fetchUserRoles (ctx context.Context , uID string ) ([]map [string ]any , error ) {
256258 page := 0
257259 finished := false
258260
@@ -290,7 +292,7 @@ func (f *Fetcher) getUserRoles(ctx context.Context, uID string) ([]map[string]an
290292 return results , nil
291293}
292294
293- func (f * Fetcher ) getOrgs (ctx context.Context , uID string ) ([]map [string ]any , error ) {
295+ func (f * Fetcher ) fetchOrgs (ctx context.Context , uID string ) ([]map [string ]any , error ) {
294296 page := 0
295297 finished := false
296298
0 commit comments