Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e007802

Browse files
committedJun 26, 2024·
review comments
1 parent f935353 commit e007802

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
 

‎scripts/docsgen/main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/coder/terraform-provider-coder/provider"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
14+
"golang.org/x/xerrors"
1415
)
1516

1617
// This script patches Markdown docs generated by `terraform-plugin-docs` to expose the original deprecation message.
@@ -35,7 +36,7 @@ func exposeDeprecationMessage(p *schema.Provider) error {
3536

3637
err := adjustDocFile(docFile, dataSource.Schema)
3738
if err != nil {
38-
return err
39+
return xerrors.Errorf("unable to adjust data-source doc file (data-source: %s): %w", dataSourceName, err)
3940
}
4041
}
4142

@@ -45,30 +46,30 @@ func exposeDeprecationMessage(p *schema.Provider) error {
4546

4647
err := adjustDocFile(docFile, resource.Schema)
4748
if err != nil {
48-
return err
49+
return xerrors.Errorf("unable to adjust resource doc file (resource: %s): %w", resourceName, err)
4950
}
5051
}
5152

5253
// Patch index
5354
docFile := filepath.Join("docs", "index.md")
5455
err := adjustDocFile(docFile, p.Schema)
5556
if err != nil {
56-
return err
57+
return xerrors.Errorf("unable to adjust index doc file: %w", err)
5758
}
5859
return nil
5960
}
6061

6162
func adjustDocFile(docPath string, schemas map[string]*schema.Schema) error {
6263
doc, err := os.ReadFile(docPath)
6364
if err != nil {
64-
return err
65+
return xerrors.Errorf("can't read the source doc file: %w", err)
6566
}
6667

6768
result := writeDeprecationMessage(doc, schemas)
6869

6970
err = os.WriteFile(docPath, result, 0644)
7071
if err != nil {
71-
return err
72+
return xerrors.Errorf("can't write modified doc file: %w", err)
7273
}
7374
return nil
7475
}
@@ -81,7 +82,8 @@ func writeDeprecationMessage(doc []byte, schemas map[string]*schema.Schema) []by
8182

8283
sch := schemas[string(propertyName)]
8384
if string(description) != sch.Description {
84-
return m // same property name but description does not match, most likely a different property
85+
log.Printf("warn: same property name `%s` but description does not match, most likely a different property", propertyName)
86+
return m
8587
}
8688
return bytes.Replace(m, []byte("Deprecated"), []byte(fmt.Sprintf("Deprecated: %s", sch.Deprecated)), 1)
8789
})

0 commit comments

Comments
 (0)
Please sign in to comment.