投稿時間:2023-06-25 20:12:14 RSSフィード2023-06-25 20:00 分まとめ(12件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
python Pythonタグが付けられた新着投稿 - Qiita Google Colabでseaborn-analyzerのpairplotが描けなくなったのは。。。 https://qiita.com/hima2b4/items/6f6d65bb4b3023416ed4 googlecolab 2023-06-25 19:52:58
python Pythonタグが付けられた新着投稿 - Qiita djangoで複数のアプリに共通して使用するmixinクラスの配置について https://qiita.com/76r6qo698/items/3f7cda55b39106713895 django 2023-06-25 19:21:05
js JavaScriptタグが付けられた新着投稿 - Qiita ブラウザゲームを作ってみよう(その15:サンプルゲーム作成その8) https://qiita.com/noji505/items/746e475fd825e6c3c535 追加 2023-06-25 19:13:38
Ruby Railsタグが付けられた新着投稿 - Qiita アプリの企画 https://qiita.com/sa109/items/4e641b134117395e3885 詳細 2023-06-25 19:35:54
海外TECH MakeUseOf Apple Reminders vs. Microsoft To Do: Which Is Better for Mac Users? https://www.makeuseof.com/apple-reminders-vs-microsoft-to-do-mac/ Apple Reminders vs Microsoft To Do Which Is Better for Mac Users Both Apple s Reminders app and Microsoft To Do are free to download on a Mac Here s what you need to know to decide which is right for you 2023-06-25 10:15:18
海外TECH DEV Community Who moved my error codes? Adding error types to your GoLang GraphQL Server https://dev.to/otterize/who-moved-my-error-codes-adding-error-types-to-your-golang-graphql-server-50p9 Who moved my error codes Adding error types to your GoLang GraphQL ServerA few months ago we at Otterize went on a journey to migrate many of our APIs including the ones used between our back end services and the ones used by our web app to GraphQL While we enjoyed many GraphQL features we faced along the way a few interesting challenges which required creative solutions Personally I find our adventure with GraphQL s errors and the error handling mechanism a fascinating one Considering GraphQL s popularity I didn t expect the GraphQL standard to miss this one very fundamental thing… Where are the error codes What happens when your code encounters a problem making an API call Coming from REST we re all used to HTTP error codes as the standard way to identify errors and take action accordingly For example when a service called another service and receives an error it may handle Not Found by creating if appropriate the missing resource while Bad Request errors abort the execution and return a client appropriate error message Now let s look at what errors look like in GraphQL It s a pretty basic error structure which consists of parts The first is “message which is a textual error message designed for human users The second is path which describes the path of the field from the query that returned the error Can you see what is missing errors message user Tobi was not found path getUser An example of a simple GraphQL errorThere are no error codes in GraphQL It might not disturb you much as a human reading the error but the absence of error codes makes it really hard to develop client side code that identifies and handles errors received from the server We started out by identifying errors by searching for specific words in the returned error message but it was clear it is not a permanent solution Any small change to the error message on the server side might fail the identification of the type on the client side Masking unexpected errors obvious in HTTP not so much in GraphQLProbably the most annoying HTTP error code is Internal Server Error as it doesn t really give any useful information But this is the one error code that matters the most regarding your application s information security ーin other words the lack of information is intentional HTTP frameworks mask any unexpected error and return HTTP Internal Server Error instead in the process also masking any sensitive information that might have been part of the error message GraphQL s spec as it turns out does not specify how servers should handle internal errors at all leaving it entirely to the choice of the frameworks creators Take for example our GoLang GraphQL framework of choice gqlgen It makes no distinction between intentional and unexpected errors all errors are returned as is to the client within the error message Internal errors which often contain sensitive information like network details and internal URIs would leak to clients easily if not caught manually by the programmer errors message Post http credential factory internal creds env dial tcp credential factory connect connection refused path createEnvironment A simulation of an unhandled internal error leaked through the GraphQL server And gqlgen is not alone in this We found several more GraphQL frameworks that don t take it upon themselves to address this problem Widely used GraphQL server implementations such as graphql go graphql and Python s graphene have the exact same gap of exposing messages of unexpected errors by default With these two points in mind it was clear that to complete our move to GraphQL we needed to find some way to add error types For one thing we would have a reliable way to identify errors in clients code And for another we could catch unexpected errors on the server side and hide their message from clients How can we add error types to GraphQL We started researching possible solutions and encountered various ways people took to solve the same problem but many of those seemed inconvenient at least for us Then we read the GraphQL errors spec and learned that errors have an optional field called “extensions ーan unstructured key value map that can be used to add any additional information to the error They even use a key called “code that contains what looks like an error code in one of their examples but we didn t see any further information Later I figured it was taken from Apollo ーsee below Knowing this we came up with a plan of adding an “errorType key to the error s “extensions map with the error code as the value For example here is the same error with the new “extensions field errors message User Tobi not found path getUser extensions errorType NotFound Digging into gqlgen s sources we discovered that the gqlgen GraphQL server uses the extension key code to report the error code of parsing and schema validation errors error errors message Cannot query field userDetails on type Query locations line column extensions code GRAPHQL VALIDATION FAILED Example of a schema validation error Note the “code key and the error code under “extensions added by the gqlgen GraphQL Server itself Unfortunately there is no built in way to extend gqlgen s error codes with additional ones We considered using the same code key for our custom error codes but eventually we preferred sticking to our separate “errorType key to avoid potential future collisions with gqlgen s error handling mechanism While working on this blog post I learned that Apollo Server the most popular GraphQL server for typescript uses a similar method for adding error codes to GraphQL It even lets you add custom errors Hopefully someday other GraphQL server projects will follow them Until then we ve got a strong indication we took the right approach Our Go implementation for typed GraphQL errorsEquipped with all the knowledge we ve built up and our plan we were ready to implement our error typing solution Throughout the rest of this post I will be describing our implementation of that plan in practice in our application Defining our application s standard error codesFirst we listed all the error codes we would like to have We started with the HTTP error codes we used to work with in REST and placed them in a GraphQL enum Putting the error codes in the schema is not mandatory but it makes it easier to refer to the same error types on both the server and client sides enum ErrorType InternalServerError NotFound BadRequest Forbidden Conflict The error codes schema We put it in a dedicated schema file called errors graphql After running go generate gqlgen generated the model package with the variables from the error codes enum The next step was to create a new typedError struct which pairs an error with the error type that should be returned to the client package typederrorstype typedError struct err error errorType model ErrorType error types are auto generated from the schema func g typedError Error string return g err Error func g typedError Unwrap error return g err func g typedError ErrorType model ErrorType return g errorType We have such a function for each of the typesfunc NotFound messageToUserFormat string args any error return amp typedError err fmt Errorf messageToUserFormat args errorType model ErrorTypeNotFound func InternalServerError messageToUserFormat string args any error return amp typedError err fmt Errorf messageToUserFormat args errorType model ErrorTypeInternalServerError Then we searched our server codebase for errors and replaced native go errors such as fmt Errorf user s not found userName with the appropriate typed error in this case typederrors NotFound user s not found userName Integrating with the GraphQL serverNext we needed to make our GraphQL server handle the typed errors returned by our application s GraphQL resolvers extract the error codes and attach them to the extensions map The way to do that using gqlgen is to implement an ErrorPresenter a hook function that lets you modify the error before it is sent to the client type TypedError interface error ErrorType model ErrorType presentTypedError is a helper function that converts a TypedError to gqlerror Error and adds the error type to the extensions fieldfunc presentTypedError ctx context Context typedErr TypedError gqlerror Error presentedError graphql DefaultErrorPresenter ctx typedErr if presentedError Extensions nil presentedError Extensions make map string interface presentedError Extensions errorType typedErr ErrorType return presentedError GqlErrorPresenter is a hook function for the gqlgen s GraphQL server that handle TypedErrors and adds the error type to the extensions field func GqlErrorPresenter ctx context Context err error gqlerror Error var typedError TypedError isTypedError errors As err amp typedError if isTypedError return presentTypedError ctx typedError return graphql DefaultErrorPresenter ctx err The GqlErrorPresenter function is our implementation of the ErrorPresenter hook func main Create a GraphQL server and make it use our error presenter srv handler NewDefaultServer server NewExecutableSchema conf srv SetErrorPresenter server GqlErrorPresenter Hooking our new error presenter into the GraphQL server Once our new ErrorPresenter is bound into the GraphQL server raised typed errors are now processed and their type is exposed to the client under the errorType extensions field errors message User Tobi not found path updateUser extensions errorType NotFound The GraphQL error reported when the server returns a typed error Masking non typed errors with InternalServerErrorIn order to prevent the leaking of sensitive information buried inside error messages we then adopted the error handling behavior of HTTP servers Instead of returning non typed errors we log them and return the typed InternalServerError instead Given the typed errors it only requires a small change to the ErrorPresenter func GqlErrorPresenter ctx context Context err error gqlerror Error var typedError TypedError isTypedError errors As err amp typedError if isTypedError return presentTypedError ctx typedError New code for masking sensitive error messages starts here var gqlError gqlerror Error if errors As err amp gqlError amp amp errors Unwrap gqlError nil It s a GraphQL schema validation parsing error generated by the server itself error message should not be masked return graphql DefaultErrorPresenter ctx err Log original error and return InternalServerError instead logrus WithError err Error Custom GraphQL error presenter got an unexpected error return presentTypedError ctx typederrors InternalServerError internal server error TypedError The GqlErrorPresenter with the new addition that replaces non typed errors with InternalServerError errors message internal server error path updateUser extensions errorType InternalServerError This is how an untyped error will be presented to the client after the change Handling errors on the client sideHaving finished our work on the server side it was time to reap the benefits and use the error codes to handle the errors properly on the client side First we need the error codes GraphQL enum to be generated as Go code We typically generate client side code using genqlient but in this case it wasn t possible because the error type enum isn t referenced by any query We solved this by running the gqlgen server side code generation tool and keeping only the generated error enums schema graphql errors graphql model filename models gen go package gqlerrorsgqlgen ymlpackage gqlerrors go generate go run github com designs gqlgen v we only need models gen for the enum so we delete the server code go generate rm generated gogenerate goOnce we generated the error codes enum we could write a simple function in the same package that extracts the error code from the genqlient error object package gqlerrorsimport github com sirupsen logrus github com vektah gqlparser v gqlerror func GetGQLErrorType err error ErrorType if errList ok err gqlerror List ok gqlerr amp gqlerror Error if errList As amp gqlerr amp amp gqlerr Extensions nil errorTypeString isString gqlerr Extensions errorType string if isString return ErrorType errorTypeString return And that s it We are ready to write code that identifies the different error codes and handles the different errors appropriately package mainfunc main if err nil if gqlerrors GetGQLErrorType err gqlerrors ErrorTypeNotFound do something to handle the NotFound error else panic err ConclusionGraphQL is a great platform but the absence of standardized error codes is a real shortcoming Although it s addressed by Apollo s GraphQL server it s unfortunate that many other GraphQL servers have yet to address it including our choice ーgqlgen By defining our own error codes and integrating them with the GraphQL server s ErrorPresenter we can easily identify errors on the client side and handle them In addition we prevent sensitive internal error messages from being sent to clients and maintain the integrity of our information security You may check out the example project to see what our implementation looks like in a small Go project and how error types affect the client s behavior This should help understand where all the snippets come together in an actual working code use case and make a great solution for the missing error codes problem 2023-06-25 10:33:56
海外TECH DEV Community Docker vs Virtual Machine Analogy https://dev.to/coderatul/docker-vs-virtual-machine-analogy-5382 Docker vs Virtual Machine Analogy IntroductionHey guys I have just started learning Docker so I wanted to share this analogy that came to my mind I believe analogies make things much clearer and easier to remember than anything else ever could Overview of Virtual MachinesLet s talk about VMs first Virtual Machines use something called a hypervisor on top of hardware A Hypervisor is a piece of software that manages hardware resources across virtual machines One may think of a Hypervisor as an HR manager On top of the hypervisor we have the virtual machine each with its own underlying OS running applications This is great if we want to run different services applications on different operating systems but it also comes with disadvantages such as Consuming a lot of resources as every virtual machine has to run a separate operating system Slow startup time Overview of DockerNow Docker has an operating system on top of which we have the Docker engine The container engine is what unpacks the container files and hands them off to the operating system kernel On top of the container engine we have applications that use the underlying operating system available on the server Containers only contain the necessary files to run a specific application which makes them Very lightweight Very fast and compact Whereas VMs use a separate operating system Now with advantages come some disadvantages which are If the OS running on the server is Linux then applications must also be Linux based They can be of different distros as Docker uses the underlying operating system s kernel By the way this is what makes Linux extremely fast as instead of using multiple OSes it uses the kernel of a single OS to manage and isolate different applications The AnalogyNow that we have an overview of how both technologies work here s the analogy One may think of a Virtual Machine as a shop that specializes in giving services of a single product category like an electronic shop or furniture store Imagine if I had to sell dairy products from a pharmacy I can t do that right I would have to build a new shop to sell dairy products Now enter Docker We can see it as a shopping complex with different shops running under the same building different applications running on the same underlying operating system I may open as many different shops as I wish subjected to availability of hardware resources Follow for more As I learn more about Docker I ll post more Analogies 2023-06-25 10:30:24
海外TECH DEV Community Top 5 Websites You'll Love as a Developer👨‍💻 https://dev.to/acode123/top-5-websites-youll-love-as-a-developer-5m5 Top Websites You x ll Love as a Developer‍There are many websites out there that can make our jobs as developers easier today I would like to share my top favorites Please feel free to comment on any websites you ve found useful in the comments below Dev DocsDev Docs is a collection of multiple API documentation in a searchable interface I ve found it extremely helpful while trying to find a perfect API for my projects Check it out RoadmapRoadmap is a website that allows you to get a personalized roadmap based on what type of developer you are Roadmap also provides additional educational content for you to further improve your skills as a developer Check it out Code BeautifyCode Beautify is a free online tool that allows you to format your code and do simple tasks like converting a decimal into a Hexidecimal number Check it out CodeCademyCodeCademy is a free website that allows you to learn skills developers need to know in an orginanized way CodeCademy also teaches you simple projects which you can do to build a portfolio Check it out CodepenCodepen is a community of developers who share and test their front end code Codepen is where you can find cool frontend projects and animation all for free Check it out I hope you enjoyed this article and found it useful Consider checking out and bookmarking some of the above tools you found useful 2023-06-25 10:19:22
ニュース BBC News - Home 999 calls: Police and fire services hit by technical glitch https://www.bbc.co.uk/news/uk-66012340?at_medium=RSS&at_campaign=KARANGA backup 2023-06-25 10:19:19
ニュース BBC News - Home Glastonbury 2023: Elton John fans reserve front row spaces at crack of dawn https://www.bbc.co.uk/news/entertainment-arts-66013113?at_medium=RSS&at_campaign=KARANGA plays 2023-06-25 10:51:31
ニュース BBC News - Home Women's Ashes 2023: England's Kate Cross superbly bowls Australia's Phoebe Litchfield https://www.bbc.co.uk/sport/av/cricket/66013082?at_medium=RSS&at_campaign=KARANGA Women x s Ashes England x s Kate Cross superbly bowls Australia x s Phoebe LitchfieldWatch Kate Cross s stunning ball to dismiss Phoebe Litchfield for as England get their first wicket of Australia s second innings on day four of the Ashes Women s Test 2023-06-25 10:45:07
ニュース Newsweek 「3年も気付かずに生活していた恐怖」 中古物件で「隠し階段」を発見した女性住人...階段の先にあったものとは https://www.newsweekjapan.jp/stories/world/2023/06/3-387.php 「隠し部屋の内部を確認したあとに、答えよりも疑問のほうが増えるとは思ってもみなかった」隠し部屋には不気味な雰囲気があったが、ワインラックが設置されていたことから、階下にこうした隠しスペースがあった理由について、ヘニングはある仮説を立てている。 2023-06-25 19:40:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)