Skip to content

Fix #161: Throw InvalidArgumentException with a clear message when an empty view name is passed to WebViewRenderer render methods - #161

Merged
samdark merged 3 commits into
masterfrom
empty-view-name
Oct 29, 2026
Merged

samdark merged 3 commits into
masterfrom
empty-view-name

Conversation

@samdark

@samdark samdark commented Oct 29, 2026

Copy link
Copy Markdown
Member

Related to yiisoft/app#478.

An empty view name has nothing to render, but WebViewRenderer didn't say so. Without a view path it failed with "The view path is not set.", and with one with "The view file ".../.php" does not exist.". For render() and renderPartial() this happened only when the response body was read, away from the call that caused it.

render(), renderPartial(), renderAsString() and renderPartialAsString() now throw InvalidArgumentException right away when the view name is empty. The message says that a response without a view, such as JSON, should be created with a response factory.

The deprecated ViewRenderer is unchanged.

An empty view name has nothing to render. Without a view path it failed with "The view path is not set.", and
with one with "The view file ".../.php" does not exist.", and only once the response body was read. The render
methods now throw InvalidArgumentException right away, with a message that points to a response factory for
responses without a view, such as JSON.
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2ff2c68) to head (0d42ab2).

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #161   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       171       173    +2     
===========================================
  Files             11        11           
  Lines            511       518    +7     
===========================================
+ Hits             511       518    +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/WebViewRenderer.php Resolved
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
@samdark samdark changed the title Throw a clear exception for an empty view name in WebViewRenderer Fix #161: Throw InvalidArgumentException with a clear message when an empty view name is passed to WebViewRenderer render methods Oct 29, 2026
@samdark
samdark merged commit a629760 into master Oct 29, 2026
15 of 26 checks passed
@samdark
samdark deleted the empty-view-name branch October 29, 2026 22:16
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