Comments (7)
Thank you for valuable input! I'm changing SaveFile()
to return error
instead of *PDF
.
IO can have errors beyond the control of the library and because SaveFile()
is normally the last method called on PDF, it does not need to return *PDF for method chaining.
Most other methods log logic errors (e.g. "unknown page size") and return *PDF. To change them to return error would mean to remove method chaining. I'm thinking of another means to query for errors in these cases: perhaps a pdf.Err() method that is set to an instance of the last error.
You can also redefine PDFErrorHandler to another function with the same signature as fmt.Println:
func(a ...interface{}) (n int, err error)
. (However, soon the error handler will be set per PDF instance, not globally.)
Your additional suggestions are welcome.
from one-file-pdf.
Do you have to have method chaining?
pdf.Err() would probably be ok, as long as errors are returned instead of logging.
from one-file-pdf.
Chaining is a good feature to have:
pdf.SetXY(5, 5).SetColor("red").DrawText("hello")
without chaining, will be:
pdf.SetXY(5,5)
pdf.SetColor("red")
pdf.DrawText("hello")
... and you can't put all these statements on one line because go fmt
would split them into many lines.
I thought of returning (*PDF, error) but that won't work:
multiple-value pdf.SetX() in single-value context
Please excuse my long explanation, its so that anyone who looks at this issue considers it,
from one-file-pdf.
If you must have chaining then store first error value inside pdf.Err. That way it would be reachable after chain of calls. Thanks.
from one-file-pdf.
I've changed SaveFile() to return error now, and some other changes (see changelog). Yet to add Err(), but soon. Again, thank you for pointing it out.
from one-file-pdf.
Hi, I've created some error handling methods in commit fd06c6f:
Clean() *PDF - clears all accumulated errors.
Errors() []error - returns a slice of all accumulated errors
PullError() error - removes and returns the first error from the errors collection
In the past few days I've made some changes to remove unnecessary error conditions that should never occur in the first place. For example, the checks for a page being active, since now there is always an active page.
Other changes I'm planning soon:
- To add the name of the method to each error message, so you can know
where in the chain the error occurred.
-
To remove some other spurious error checks: e.g. the "Rune out of range" error in textWidthPt1000() that should never happen in the first place, because we're not using Unicode yet, and even then it won't be needed.
-
There may be minor changes/fixes to error handling over the weekend.
from one-file-pdf.
- Error messages now include the name of the method that produced the error
- Clean(), Errors() and PullError() have unit tests, work as expected
from one-file-pdf.
Related Issues (11)
- SaveFile method creates unreadable file HOT 4
- PNG embedding is slow
- NextLine() calc seems wrong
- Larger charset HOT 2
- Streaming mode
- ZapfDingbats icons not rendered on Debian Linux 9 (squeeze) - probably extraneous issue HOT 2
- PDF Metadata not properly encoded HOT 5
- No support for simple color (RGB) PNG images HOT 8
- How to support Unicode in the PDF format? HOT 5
- png_images.pdf (demo) is larger than estimated HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from one-file-pdf.