Skip to content

Commit

Permalink
Fix javascript processor docs
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Todor <todormihai@gmail.com>
  • Loading branch information
mihaitodor committed Dec 19, 2024
1 parent ede148a commit c7a2136
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ All notable changes to this project will be documented in this file.

- `avro` scanner now emits metadata for the Avro schema it used along with the schema fingerprint (@rockwotj)

### Fixed

- The `code` and `file` fields on the `javascript` processor docs no longer erroneously mention interpolation support. (@mihaitodor)

## 4.44.0 - 2024-12-13

### Added
Expand Down
2 changes: 0 additions & 2 deletions docs/modules/components/pages/processors/javascript.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ This processor is implemented using the https://github.com/dop251/goja[github.co
=== `code`
An inline JavaScript program to run. One of `code` or `file` must be defined.
This field supports xref:configuration:interpolation.adoc#bloblang-queries[interpolation functions].
*Type*: `string`
Expand All @@ -56,7 +55,6 @@ This field supports xref:configuration:interpolation.adoc#bloblang-queries[inter
=== `file`
A file containing a JavaScript program to run. One of `code` or `file` must be defined.
This field supports xref:configuration:interpolation.adoc#bloblang-queries[interpolation functions].
*Type*: `string`
Expand Down
10 changes: 5 additions & 5 deletions internal/impl/javascript/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ Although technically possible, it is recommended that you do not rely on the glo
== Functions
`+description.String()+`
`).
Field(service.NewInterpolatedStringField(codeField).
Field(service.NewStringField(codeField).
Description("An inline JavaScript program to run. One of `"+codeField+"` or `"+fileField+"` must be defined.").
Optional()).
Field(service.NewInterpolatedStringField(fileField).
Field(service.NewStringField(fileField).
Description("A file containing a JavaScript program to run. One of `"+codeField+"` or `"+fileField+"` must be defined.").
Optional()).
Field(service.NewStringListField(includeField).
Expand Down Expand Up @@ -174,23 +174,23 @@ func newJavascriptProcessorFromConfig(conf *service.ParsedConfig, mgr *service.R
code, _ := conf.FieldString(codeField)
file, _ := conf.FieldString(fileField)
if file == "" && code == "" {
return nil, fmt.Errorf("either a `%v` or `%v` must be specified", codeField, fileField)
return nil, fmt.Errorf("either a `%s` or `%s` must be specified", codeField, fileField)
}

filename := "main.js"
if file != "" {
// Open file and read code
codeBytes, err := service.ReadFile(mgr.FS(), file)
if err != nil {
return nil, fmt.Errorf("failed to open target file: %w", err)
return nil, fmt.Errorf("failed to open target file: %s", err)
}
filename = file
code = string(codeBytes)
}

program, err := goja.Compile(filename, code, false)
if err != nil {
return nil, fmt.Errorf("failed to compile javascript code: %v", err)
return nil, fmt.Errorf("failed to compile javascript code: %s", err)
}

logger := mgr.Logger()
Expand Down

0 comments on commit c7a2136

Please sign in to comment.