Skip to content

Commit 9609316

Browse files
committed
Update error handle in case there's panic error or issue in resource schema
1 parent e04b5ac commit 9609316

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

.github/workflows/document-lint.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,24 @@ jobs:
3737
- name: run document lint checker
3838
if: steps.changed-files.outputs.has-files == 'true'
3939
run: |
40-
if make document-lint; then
40+
set +e
41+
make document-lint
42+
exit_code=$?
43+
set -e
44+
45+
if [ $exit_code -eq 0 ]; then
4146
echo "::notice::Document lint success."
42-
else
47+
exit 0
48+
elif [ $exit_code -eq 1 ]; then
4349
echo "::warning::Document lint failed. Please fix the issues."
4450
exit 1
51+
elif [ $exit_code -eq 2 ]; then
52+
echo "::warning::Document lint encountered a panic. This may indicate an issue with the linter itself or resource schema."
53+
echo "::notice::Allowing workflow to continue despite panic."
54+
exit 0
55+
else
56+
echo "::error::Document lint exited with unexpected code: $exit_code"
57+
exit 1
4558
fi
4659
4760
- name: skip document lint checker

internal/services/resource/resource_provider_registration_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (r ResourceProviderRegistrationResource) Attributes() map[string]*pluginsdk
8888
return map[string]*pluginsdk.Schema{
8989
"test_missing_attr_in_typed_resource": {
9090
Type: pluginsdk.TypeString,
91-
Required: true,
91+
Computed: true,
9292
},
9393
}
9494
}

internal/tools/document-lint/check/check_resource_all.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func DiffAll(regs Resources, dryRun bool) *DiffResult {
124124
var catName string
125125

126126
sch := schema.NewResource(res.schema, res.name)
127+
if sch == nil {
128+
// failed to create resource schema, skipping
129+
continue
130+
}
127131
rd := NewResourceDiff(sch)
128132
if !dryRun {
129133
md.FixFileNormalize(rd.MDFile)

internal/tools/document-lint/schema/resource_schema.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package schema
55

66
import (
7+
"fmt"
78
"strings"
89

910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -32,18 +33,25 @@ type Resource struct {
3233
PossibleValues map[string][]string // possible values for key(property path)
3334
}
3435

35-
func ResourceForSDKType(res sdk.Resource) *schema.Resource {
36+
func ResourceForSDKType(res sdk.Resource) (*schema.Resource, error) {
3637
r := sdk.NewResourceWrapper(res)
37-
ins, _ := r.Resource()
38-
return ins
38+
ins, err := r.Resource()
39+
if err != nil {
40+
return nil, fmt.Errorf("failed to get resource schema for %s: %v", res.ResourceType(), err)
41+
}
42+
return ins, nil
3943
}
4044

4145
// NewResourceByTyped NewResource ...
4246
// r is Schema.Resource or Typed SDK Resource
4347
func NewResourceByTyped(r sdk.Resource) *Resource {
4448
s := &Resource{}
4549
s.SDKResource = r
46-
s.Schema = ResourceForSDKType(r)
50+
schema, err := ResourceForSDKType(r)
51+
if err != nil {
52+
return nil
53+
}
54+
s.Schema = schema
4755
s.ResourceType = r.ResourceType()
4856
s.Init()
4957
return s
@@ -68,6 +76,10 @@ func NewResource(r interface{}, rType string) *Resource {
6876
}
6977

7078
func (r *Resource) Init() {
79+
if r.Schema == nil {
80+
return
81+
}
82+
7183
if r.SDKResource != nil {
7284
// SDKResource is a type of interface, have to get the real
7385
// vd := reflect.ValueOf(r.SDKResource).Interface()

0 commit comments

Comments
 (0)