Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors of file IO #32

Closed
wants to merge 1 commit into from
Closed

Handle errors of file IO #32

wants to merge 1 commit into from

Conversation

nkzawa
Copy link

@nkzawa nkzawa commented Feb 25, 2019

This PR fixes the problem that template.render("template.html") can print the template.html string as the rendering result when an error happened on file load.

Unfortunately, this PR is not a perfect solution because it can still render a file name when the file doesn't exist. This module should support a method for treating only file paths something like template.renderfile IMHO. Additionally, I hope the methods to return an error as a result like ok, err = template.render().

I know that you can define your own template.load but it's troublesome since the loadngx module is not that simple. Hope having a nicer default.

bungle added a commit that referenced this pull request Feb 20, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 20, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
@bungle bungle mentioned this pull request Feb 20, 2020
bungle added a commit that referenced this pull request Feb 20, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 21, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 21, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 21, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function` (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function` (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function` (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function` (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function` (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 24, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 24, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this pull request Feb 24, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
@bungle
Copy link
Owner

bungle commented Feb 24, 2020

With 2.0 there is render_file etc. Also there is a safe mode too, e.g.:

local template = require "resty.template.safe"

That will not error but return nil, err. Thus I am closing this.

@bungle bungle closed this Feb 24, 2020
@nkzawa nkzawa deleted the io-errors branch February 24, 2020 14:27
olegrok pushed a commit to tarantool/template that referenced this pull request May 9, 2020
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (bungle#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (bungle#36)

- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (bungle#32)

- Wrong template returned when using multiple server blocks (bungle#25)
- Add a pure lua configure method (bungle#23, #7)
olegrok pushed a commit to tarantool/template that referenced this pull request May 9, 2020
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (bungle#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (bungle#36)

- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (bungle#32)

- Wrong template returned when using multiple server blocks (bungle#25)
- Add a pure lua configure method (bungle#23, #7)
olegrok pushed a commit to tarantool/template that referenced this pull request May 9, 2020
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (bungle#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (bungle#36)

- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (bungle#32)

- Wrong template returned when using multiple server blocks (bungle#25)
- Add a pure lua configure method (bungle#23, #7)
olegrok pushed a commit to tarantool/template that referenced this pull request Oct 1, 2020
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (bungle#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (bungle#36)

- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (bungle#32)

- Wrong template returned when using multiple server blocks (bungle#25)
- Add a pure lua configure method (bungle#23, #7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants